thumbnail image in week view widget – make it link to event and not `/`…

Home Forums Welcome! Pre-Sales Questions thumbnail image in week view widget – make it link to event and not `/`…

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1188724
    christina canning
    Guest

    Hi,
    We added thumbnails to the output of the week view following the directions in the themers-guide and that works great; but we need to link the image to the event, the way the heading does. How would we do that?

    So far, we’ve tried copying these two functions from general.php and link.php into our functions.php (changing the names to avoid conflict…)

    function tribe_event_featured_image( $post_id = null, $size = 'full', $link = true ) {
            if ( is_null( $post_id ) ) {
                $post_id = get_the_ID();
            }
     
            /**
             * Provides an opportunity to modify the featured image size.
             *
             * @param string $size
             * @param int    $post_id
             */
            $image_html     = get_the_post_thumbnail( $post_id, apply_filters( 'tribe_event_featured_image_size', $size, $post_id ) );
            $featured_image = '';
     
            /**
             * Controls whether the featured image should be wrapped in a link
             * or not.
             *
             * @param bool $link
             */
            if ( ! empty( $image_html ) && apply_filters( 'tribe_event_featured_image_link', $link ) ) {
                $featured_image .= '<div class="tribe-events-event-image"><a href="' . esc_url( tribe_get_event_link() ) . '">' . $image_html . '</a></div>';
            } elseif ( ! empty( $image_html ) ) {
                $featured_image .= '<div class="tribe-events-event-image">' . $image_html . '</div>';
            }
     
            /**
             * Provides an opportunity to modify the featured image HTML.
             *
             * @param string $featured_image
             * @param int    $post_id
             * @param string $size
             */
            return apply_filters( 'tribe_event_featured_image', $featured_image, $post_id, $size );
        }
     
    function tribe_get_event_link( $postId = null, $full_link = false ) { 
    $url = Tribe__Events__Main::instance()->getLink( 'single', $postId );
     
            if ( '' != get_option( 'permalink_structure' ) ) $url = trailingslashit( $url );
     
            if ( $full_link ) {
                $title_args = array( 'post' => $postId, 'echo' => false );
                $name = get_the_title( $postId );
                $attr_title = the_title_attribute( $title_args );
                $link = ! empty( $url ) && ! empty( $name ) ? '<a href="' . esc_url( $url ) . '" title="'.$attr_title.'"">' . $name . '</a>' : false;
            } else {
                $link = $url;
            }
     
            return apply_filters( 'tribe_get_event_link', $link, $postId, $full_link, $url );

    IN OUR FUNCTIONS.PHP FILE WE HAVE:

    In our functions file we have:
    
    function iw_tribe_get_event_link( $postId = null, $full_link = true ) {
    
    $url = Tribe__Events__Main::instance()->getLink( 'single', $postId );
    
    if ( '' != get_option( 'permalink_structure' ) ) $url = trailingslashit( $url );
    
    if ( $full_link ) {
    $title_args = array( 'post' => $postId, 'echo' => false );
    $name = get_the_title( $postId );
    $attr_title = the_title_attribute( $title_args );
    $link = ! empty( $url ) && ! empty( $name ) ? '<a href="' . esc_url( $url ) . '" title="'.$attr_title.'"">' . $name . '</a>' : false;
    } else {
    $link = $url;
    }
    
    return apply_filters( 'tribe_get_event_link', $link, $postId, $full_link, $url );
    }
    
    function iw_tribe_event_featured_image( $post_id = null, $size = 'full', $link = true ) {
    if ( is_null( $post_id ) ) {
    $post_id = get_the_ID();
    }
    
    /**
    * Provides an opportunity to modify the featured image size.
    *
    * @param string $size
    * @param int $post_id
    */
    $image_html = get_the_post_thumbnail( $post_id, apply_filters( 'tribe_event_featured_image_size', $size, $post_id ) );
    $featured_image = '';
    
    /**
    * Controls whether the featured image should be wrapped in a link
    * or not.
    *
    * @param bool $link
    */
    if ( ! empty( $image_html ) && apply_filters( 'tribe_event_featured_image_link', $link ) ) {
    $featured_image .= '<div class="tribe-events-event-image"><a href="' . esc_url( iw_tribe_get_event_link() ) . '">' . $image_html . '</a></div>';
    } elseif ( ! empty( $image_html ) ) {
    $featured_image .= '<div class="tribe-events-event-image">' . $image_html . '<br>'.$link.'</div>';
    }
    
    /**
    * Provides an opportunity to modify the featured image HTML.
    *
    * @param string $featured_image
    * @param int $post_id
    * @param string $size
    */
    return apply_filters( 'tribe_event_featured_image', $featured_image, $post_id, $size );
    }
    
    And in within our theme we have, in single-event.php:
    
    <div id="tribe-events-event-<?php echo esc_attr( $event->ID ); ?>" class="<?php tribe_events_event_classes( $event->ID ) ?> tribe-this-week-event" >
    
    <a href="<?php echo esc_url( tribe_get_event_link( $event->ID ) ); ?>" rel="bookmark">
    <?php
    echo iw_tribe_event_featured_image($event->ID, 'thumbnail');
    ?>
    </a>
    
    <h2 class="entry-title summary">
    <a href="<?php echo esc_url( tribe_get_event_link( $event->ID ) ); ?>" rel="bookmark"><?php echo esc_html( $event->post_title ); ?></a>
    </h2>
    
    <div class="duration">
    <?php echo tribe_events_event_schedule_details( $event->ID ) ?>
    
    </div>
    
    <div class="fn org tribe-venue">
    <?php echo tribe_get_venue_link( $event->ID ); ?>
    </div>
    
    </div>
    #1188759
    Nico
    Member

    Hey Chris,

    I’ve already replied to your thread here: https://theeventscalendar.com/support/forums/topic/thumbnail-image-in-week-view-widget-make-it-link-to-event-and-not-/

    I’m closing this one out and marking it as a duplicate, let’s continue the conversation in the original thread!

    Best,
    Nico

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘thumbnail image in week view widget – make it link to event and not `/`…’ is closed to new replies.