Hi, on my venues page there is the code to show the events happening at that venue.
How can I limit this to show only the next 5 events?
Thanks
<?php while ( have_posts()) : the_post(); ?>
<div class="sidebareventbox">
<div class="sidebarhomefoodtitle">
<a href="<?php the_permalink(); ?>"><?php the_title();?></a>
</div>
<!-- Output the date of the occurrence-->
<?php
//Format date/time according to whether its an all day event.
//Use microdata http://support.google.com/webmasters/bin/answer.py?hl=en&answer=176035
if( eo_is_all_day() ){
$format = 'l jS F';
$microformat = 'Y-m-d';
}else{
$format = 'l jS F'.get_option('time_format');
$microformat = 'c';
}?>
<div class="sidebardate"><time itemprop="startDate" datetime="<?php eo_the_start($microformat); ?>"><?php eo_the_start($format); ?></time></div>
<div class="sidebaraboutmusic"><?php the_excerpt(); ?></div>
<div class="sidebarlink"><a href="<?php the_permalink(); ?>">Click here for more details</a></div>
</div>
<?php endwhile; ?>
Ross Gosling
Hi Ross,
The following should work:
add_action( 'pre_get_posts', 'gosling_limit_events_on_venue_page' );
function gosling_limit_events_on_venue_page( $query ){
if( $query->is_main_query() && is_tax( 'event-venue' ) ){
$query->set( 'posts_per_page', 5 );
}
}
This code should go in a utility plug-in (but will also work in your theme’s functions.php
).
Stephen Harris