Limit number of events shown on venue page

WordPress Event Management, Calendars & Registration Forums General Question Limit number of events shown on venue page

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 10 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5750

    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-->

                    &lt;?php
                    //Format date/time according to whether its an all day event.
                    //Use microdata http://support.google.com/webmasters/bin/answer.py?hl=en&amp;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';
                    }?&gt;
                    &lt;div class="sidebardate"&gt;&lt;time itemprop="startDate" datetime="&lt;?php eo_the_start($microformat); ?&gt;"&gt;&lt;?php eo_the_start($format); ?&gt;&lt;/time&gt;&lt;/div&gt;
    
                    &lt;div class="sidebaraboutmusic"&gt;&lt;?php the_excerpt(); ?&gt;&lt;/div&gt;
    
                    &lt;div class="sidebarlink"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;Click here for more details&lt;/a&gt;&lt;/div&gt;
    

    </div>
    <?php endwhile; ?>

    Ross Gosling
    #5751

    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
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.