Captions for featured images on tribe_events posts not displaying

Home Forums Calendar Products Events Calendar PRO Captions for featured images on tribe_events posts not displaying

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #956152
    kqed
    Participant

    Hi – our editors are creating captions for the featured images associated with events (tribe_events post type), but they’re not displaying using the same methods for rendering images on other posts.

    It looks like you have your own ‘featured image display’ code in your template_tags.php file. Any hints on how we can extend your function to return a caption?

    Our code that does it for other featured images:

    function get_the_feature_caption() {
    global $post;
    $thumbnail_id = get_post_thumbnail_id($post->ID);
    $thumbnail_image = get_posts(array(‘p’ => $thumbnail_id, ‘post_type’ => ‘attachment’));
    if ($thumbnail_image && isset($thumbnail_image[0])) {
    if (! empty($thumbnail_image[0]->post_excerpt)) {
    $caption = $thumbnail_image[0]->post_excerpt;
    }
    }
    return $caption;
    }

    function get_image_credit($post) {
    $featured_image_id = get_post_thumbnail_id($post);
    $caption = get_the_feature_caption($post);
    $image_credit = get_post_meta($featured_image_id, ‘image_credit’, true);

    if (empty( $caption)) { $figclass=’credit-only’; }

    if (! empty( $caption) || ! empty( $image_credit ) ) {
    if (! empty( $image_credit )) {
    $credit = ‘<figcaption class=”‘ . $figclass . ‘”><p>’ . $caption . ‘ (‘ .$image_credit . ‘)</p></figcaption>’;
    } else {
    $credit = ‘<figcaption><p>’ . $caption . ‘</p></figcaption>’;
    }
    return $credit;
    }
    }

    Your code for returning a featured image:
    function tribe_event_featured_image( $post_id = null, $size = ‘full’, $link = true ) {
    if ( is_null( $post_id ) ) {
    $post_id = get_the_ID();
    }
    $image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
    $featured_image = ”;

    //if link is not specifically excluded, then include
    if ( ! empty( $image_src ) && $link ) {
    $featured_image .= ‘<div class=”tribe-events-event-image”>
    </div>’;
    } elseif ( ! empty( $image_src ) ) {
    $featured_image .= ‘<div class=”tribe-events-event-image”></div>’;
    }

    return apply_filters( ‘tribe_event_featured_image’, $featured_image, $post_id, $size, $image_src );
    }

    #956245
    George
    Participant

    Hey Kevin!

    There are a few ways to go about doing this – one would be to manually edit various template files for The Events Calendar, replacing instances of our custom Tribe featured-image functions with default WordPress ones (or your own ones).

    If you’re curious about that process, our “official Themer’s Guide” has a ton of great information on how to do this → http://theeventscalendar.com/knowledgebase/themers-guide/

    A much easier way to do this, however, might be to just use the filter in the Tribe function – it’s the ‘tribe_event_featured_image’ filter being run at the bottom of the code that you posted here, for example.

    I wrote up an example snippet for you here, in this Gist – check out the example-snippet.php file here, and drop that code (or something similar to it) into your theme’s functions.php file → https://gist.github.com/momnt/21fd06d92ffbce99cd7a

    Note: the bottom file in that Gist is a version of your own get_the_feature_caption() function that I made – I ran into some PHP notices with your original version and couldn’t get it to work correctly, so I simplified the function and it worked better for me.

    I hope this information helps – try out the snippet, play around with modifying it a bit, and let us know if it seems like a promising solution here.

    Cheers!
    George

    #956436
    kqed
    Participant

    Thanks for the help, that worked!

    #957218
    George
    Participant

    Glad to hear it! Best of luck with your site! 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Captions for featured images on tribe_events posts not displaying’ is closed to new replies.