2

If anyone out there is familiar with Event Organiser templates. I could use some help. I am trying to limit it to 5 per page and add custom pagination. I can't seem to edit the loop in eo-loop-events.php file to add a custom query to limit it to 5 per page.

I've tried the shortcode and looked at their documentation all afternoon and am getting nowhere. I figure there is probably an easy way to do this and I am missing it or I can't do this with the free version.

Any help would be appreciated.

Tim Herbert
  • 120
  • 10

1 Answers1

0

I just had to implement pagination for my wp events organiser template. This is inside widget-event-list.php but will probably work in other templates. This is copy pasted from a working example within the template.

This utilizes the WP_Query loop instead of the $eo_event_loop() that the template uses by default. The WP_Query loop has arguments to get "event" data only.

Fortunately, the event organiser functions (like eo_get_event_datetime_format()) still work.

In this example, I am only outputting the title in the <h4> tag.

This solution was inspired by this answer to another question.

<h1>Paginated Query Area</h1>
<?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $args = array(
        'post_type'=>'event', // Your post type name
        'posts_per_page' => 3,
        'paged' => $paged,
    );

    $loop = new WP_Query( $args );
?>
<?php if ( $loop->have_posts() ): ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <?php
        //Generate HTML classes for this event
        $eo_event_classes = eo_get_event_classes();

        //For non-all-day events, include time format
        $format = eo_get_event_datetime_format();
    ?>

    <h4 class="event-title"><?php the_title(); ?></h4>

    <?php endwhile; ?>

    <div class="upcoming-pagination">
        <?php // Pagination display
            $total_pages = $loop->max_num_pages;

            if ($total_pages > 1){

                $current_page = max(1, get_query_var('paged'));

                echo paginate_links(array(
                    'base' => get_pagenum_link(1) . '%_%',
                    'format' => '/page/%#%',
                    'current' => $current_page,
                    'total' => $total_pages,
                    'prev_text'    => __('« prev'),
                    'next_text'    => __('next »'),
                ));
            }
        ?>
    </div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
Matthew Rideout
  • 7,330
  • 2
  • 42
  • 61
  • 1
    Didn’t realize this was still out there and honestly don’t remember it now. I solved it somehow but forgot to mark this resolved. I marked yours as an answer as it might help someone in the future – Tim Herbert Dec 11 '19 at 05:35