Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Stephen Harris

    (@stephenharris)

    I’m afraid this isn’t possible (in general). There is only one page for an event (regardless of whether it recurs or not – there are performance/SEO concerns which influenced this decision). So the idea of a ‘next’ event after this event doesn’t make sense: ‘next’ after which date of this event?

    Of course, if you’re dealing solely with single events, then yes it does make sense – but that’s why it doesn’t exist ‘out of the box’.

    If you are dealing with single events, first find the next event (the event which starts after this event (and is not this event)):

    $next_event = eo_get_events( array(
       'post_not__in' => array( get_the_ID() ),
       'event_start_after' => eo_get_the_start( 'Y-m-d H:i:s' )
    ) );
    if( $next_event ){
       $permalink = get_permalink( $next_event[0] );
       printf( '<a href="%s">Next event</a>', $permalink );
    }

    (You’ll want that ‘in the loop’).

    Similar code for the ‘previous’ events:

    $next_event = eo_get_events( array(
       'post_not__in' => array( get_the_ID() ),
       'event_start_before' => eo_get_the_start( 'Y-m-d H:i:s' ),
       'showpastevents' => true,
    ) );

    (Code is completely untested and may have syntax errors)

    (The whole thing can be complicated more if you throw in the fact that events can overlap: In the above I’ve taken next to mean the event which starts next, which probably makes the most sense).

    Thread Starter Marzypann

    (@marzypann)

    Hi Stephen – thanks for this.

    What I was actually after was a simple ‘next‘ button that would allow me to navigate to the next post/event similar to the way I can on a blog page.

    Ideally this would appear at the bottom of each single event so that a user can browse back through each thing that has happened in the past – or browse forward to see the latest/next event, if they are currently on a past event.

    I haven’t tried with your code yet, as I wanted to make sure I explained this properly first.

    Have I made much sense?

    Plugin Author Stephen Harris

    (@stephenharris)

    Hi Marzypann,

    Yes the above snippets do that. But keep in mind my caveat about what it means for an event to be ‘next’. For recurring events there is still only one page, so it does make sense to say ‘go to the next event’ – since the current page has multiple dates to go to ‘next’ from.

    So the above only really make sense if none of your events are recurring.

    Thread Starter Marzypann

    (@marzypann)

    Thank you.

    Where exactly would I put this code? I’m new to this and what to make sure I have the right .php file.

    Also, you mentioned this code would need to be included ‘in the loop‘ – I apologise but I’m still unsure where to put it.

    In the index.php it’s:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    And ends:

    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    But I have a feeling this isn’t exactly what you’re referring to…?

    Thread Starter Marzypann

    (@marzypann)

    No worries, fixed.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do you add Previous/Next buttons to a single event?’ is closed to new replies.