Home › Forums › Calendar Products › Events Calendar PRO › Customize Related Events Template
- This topic has 5 replies, 2 voices, and was last updated 6 years, 10 months ago by Jennifer.
-
AuthorPosts
-
May 24, 2017 at 11:00 pm #1288726ChrisParticipant
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.
May 26, 2017 at 11:59 am #1289581JenniferKeymasterHi 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
May 28, 2017 at 4:54 pm #1290166ChrisParticipantStill 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' ) ?> »</a> </div><!-- .tribe-events-list-event-description --> </div> </div> </div> <?php endforeach; ?> <?php endif;
May 30, 2017 at 7:26 am #1290743JenniferKeymasterHi 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.
May 30, 2017 at 12:47 pm #1290980ChrisParticipantThanks Jennifer,
Reverting to tribe_events_get_the_excerpt( $post ) seemed to do the trick!
Much appreciated
May 30, 2017 at 5:27 pm #1291096JenniferKeymasterAwesome, 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
-
AuthorPosts
- The topic ‘Customize Related Events Template’ is closed to new replies.