Customize Related Events Template

Home Forums Calendar Products Events Calendar PRO Customize Related Events Template

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1288726
    Chris
    Participant

    I have a problem with adding an excerpt to the related events loop. It’s repeating the content from the single event above it: http://tomthomson.org/event/ssspun/

    I am using <?php echo get_the_excerpt( ); ?>

    I’d also like to customize the query so that only one related event displays.

    Please advise.

    • This topic was modified 6 years, 10 months ago by Chris. Reason: Forgot to mention the php function i was using
    • This topic was modified 6 years, 10 months ago by Jennifer.
    #1289581
    Jennifer
    Keymaster

    Hi Chris,

    Thanks for reaching out! I’d be happy to help you with this.

    To only show one related event, you can add this to your functions.php file:


    function tribe_limit_related_events( $args ) {
    $args['posts_per_page'] = 1;
    return $args;
    }

    add_filter( 'tribe_related_posts_args', 'tribe_limit_related_events' );

    Regarding the excerpt – get_the_excerpt() will work, but you need to pass it the $post argument. You can copy the template for related events, found at plugins/events-calendar-pro/src/views/pro/related-events.php, into your child theme and add



    inside the foreach loop, wherever you’d like the excerpt to show up.

    As far as customizing the query, our themer’s guide is definitely worth taking a look at. This post also has some helpful info on customizing related events.

    Let me know how that works for you!

    Thanks,

    Jennifer

    #1290166
    Chris
    Participant

    Still having a problem with the excerpt: http://tomthomson.org/event/ssspun/

    Below is the code from my copy of the related-events.php template

    <?php
    /**
     * Related Events Template
     * The template for displaying related events on the single event page.
     *
     * You can recreate an ENTIRELY new related events view by doing a template override, and placing
     * a related-events.php file in a tribe-events/pro/ directory within your theme directory, which
     * will override the /views/pro/related-events.php.
     *
     * You can use any or all filters included in this file or create your own filters in
     * your functions.php. In order to modify or extend a single filter, please see our
     * readme on templates hooks and filters
     *
     * @package TribeEventsCalendarPro
     *
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	die( '-1' );
    }
    
    $posts = tribe_get_related_posts( array ( 'posts_per_page' => 1));
    
    if ( is_array( $posts ) && ! empty( $posts ) ) : ?>
    
    <h5>Also On View</h5>
    
    	<?php foreach ( $posts as $post ) : ?>
    <div  class="x-container max "  style="margin: 0px auto;padding: 0px; margin-bottom:15px;">
    
    			<div  class="x-column x-sm x-1-3" style="padding: 0px;" >
    
    		<?php $thumb = ( has_post_thumbnail( $post->ID ) ) ? get_the_post_thumbnail( $post->ID, 'large' ) : '<img src="' . esc_url( trailingslashit( Tribe__Events__Pro__Main::instance()->pluginUrl ) . 'src/resources/images/tribe-related-events-placeholder.png' ) . '" alt="' . esc_attr( get_the_title( $post->ID ) ) . '" />'; ?>
    		<div class="tribe-related-events-thumbnail">
    			<a href="<?php echo esc_url( tribe_get_event_link( $post ) ); ?>" class="url" rel="bookmark"><?php echo $thumb ?></a>
    		</div>
    
    </div>
    			<div  class="x-column x-sm x-2-3" style="padding: 0px;" >
    
    		<div class="tribe-related-event-info">
    			<h6 class="tribe-related-events-title"><a href="<?php echo tribe_get_event_link( $post ); ?>" class="tribe-event-url" rel="bookmark"><?php echo get_the_title( $post->ID ); ?></a></h6>
    			
    			<div class="tribe-events-list-event-description tribe-events-content">
    	<?php echo get_the_excerpt( $post ); ?>
    	<a href="<?php echo esc_url( tribe_get_event_link() ); ?>" class="tribe-events-read-more" rel="bookmark"><?php esc_html_e( 'Find out more', 'the-events-calendar' ) ?> &raquo;</a>
    </div><!-- .tribe-events-list-event-description -->
    
    		</div>
    
    			</div>
    
    </div>
    
    	<?php endforeach; ?>
    <?php
    endif;
    
    #1290743
    Jennifer
    Keymaster

    Hi Chris,

    I’m surprised you’re still getting that issue with the template you sent me. I copied yours into my testing site, and it was giving me the correct excerpt. Can you verify that you have it saved in /tribe-events/pro/ in your child theme?

    One other thing you can do is use tribe_events_get_the_excerpt( $post ) instead of get_the_excerpt( $post ). This one is meant to be used in our events templates.

    #1290980
    Chris
    Participant

    Thanks Jennifer,

    Reverting to tribe_events_get_the_excerpt( $post ) seemed to do the trick!

    Much appreciated

    #1291096
    Jennifer
    Keymaster

    Awesome, glad to hear that worked for you!

    I’ll go ahead and close out this thread, but if you have any further questions, please feel free to open a new one!

    Thanks,

    Jennifer

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Customize Related Events Template’ is closed to new replies.