Tagged: , ,

  • This topic contains 1 voice and has 0 replies.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #21581

    dnicinski
    Participant

    Hello,

    How can we add Previous / Next buttons to the bottom of single events?

    Currently we have this code in place in single-event.php but it is not working with the recurring events.

    
    <!-- Next / Previous Buttons -->
    <nav role="navigation" aria-label="Pagination" class="pagdisplay"><ul id="nextPrevPages">
    <?php
            $today = get_post_meta( get_the_ID(), '_event_occurrence_date', true );
            $the_query = new WP_Query(array(
                'post_type'        => 'event',
                'posts_per_page'   => 1,
                'meta_key'         => '_event_occurrence_date',
                'orderby'          => 'meta_value',
                'order'            => 'ASC',
                'meta_query' => array(
                     array(
                        'key'        => '_event_occurrence_date',
                        'compare'    => '>',
                        'value'        => $today,
                    )
                ),
            ));
    
            // The Loop
            if ($the_query->have_posts()) {
                while ( $the_query->have_posts() ) {
                    $the_query->the_post();
                    echo '<li class="next">';
                    echo '<a class="next page-numbers" href="'. get_permalink( $the_query->ID ) .'">';
                        if (function_exists('pll__')) {
                          echo '<span class="pagination-label">'.pll__('Next').'</span>';
                        } else {
                          echo '<span class="pagination-label">Next</span>';
                        }
                    echo get_the_title().'</a></li>';
                }
            }
    
            $the_queryP = new WP_Query(array(
                'post_type'          => 'event',
                'posts_per_page'     => 1,
                'meta_key'           => '_event_occurrence_date',
                'orderby'            => 'meta_value',
                'order'              => 'DESC',
                'meta_query' => array(
                     array(
                        'key'        => '_event_occurrence_date',
                        'compare'    => '<',
                        'value'        => $today,
                    )
                ),
            ));
    
            // The Loop
            if ($the_queryP->have_posts()) {
                while ( $the_queryP->have_posts() ) {
                    $the_queryP->the_post();
                    echo '<li class="previous">';
                    echo '<a class="next page-numbers" href="'. get_permalink( $the_queryP->ID ) .'">';
                        if (function_exists('pll__')) {
                          echo '<span class="pagination-label">'.pll__('Back').'</span>';
                        } else {
                          echo '<span class="pagination-label">Previous</span>';
                        }
                    echo get_the_title().'</a></li>';
                }
            }
            // Restore original Post Data
            wp_reset_query();
    ?>
    </ul></nav><br /><br /><br />
    

    Any help would be appreciated.

    Thank you

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.