Pagination in kirby documentation not working

I’ve been over this a bunch of times now. I’m following the pagination documented on the kirby website but when i skip to my second page it shows items from the first page.

This is my code:

                    <div class="col-md-1 content-block"></div>
                    	<div class="col-md-10 content-block">
                            <ul class="events-list">
                            $list = $page->children()->paginate(3);
                            $pagination = $list->pagination();
                            $i = 0;
                                foreach($list as $item): ?>
                                    <li class="event-list-item">
                                        <?php $calendar = $page->children()->nth($i)->calendar()->yaml();
                                        foreach($calendar as $calendarEntry): ?>
                                                <span class="event-date">
                                                    <span class="date">
                                                            echo date('j',$eventday);  
                                                    <span class="month">
                                                            echo date('M',$eventmonth);  
                                                    <span class="year">
                                                            echo date('Y',$eventmonth);  
                                                <div class="event-list-cont">
                                                    <span class="meta-data">Starts:
                                                        <?php $eventday=strtotime($calendarEntry['_begin_date']);
                                                        echo date('l',$eventday);  ?>, 
                                                        <?php $eventstarttime=strtotime($calendarEntry['_begin_time']);
                                                        echo date('g:i A',$eventstarttime); $eventday=strtotime($calendarEntry['_end_date']);
                                                        if ($eventday){ ?>
                                                            | Finishes: <?php echo date('l',$eventday); ?>,
                                                            <?php }  ?>
                                                        <?php $eventendtime=strtotime($calendarEntry['_end_time']);
                                                        if($eventendtime) {
                                                            echo date('g:i A',$eventendtime);
                                                            }  ?></span>
                                                    <h4 class="post-title"><a href="<?php echo page('events')->children()->nth($i)->url(); ?>"><?php echo $calendarEntry['eventname'] ?></a></h4>
                                                        <?php echo page('events')->children()->nth($i)->eventwriteup()->excerpt(250); ?> <a href="<?php echo page('events')->children()->nth($i)->url(); ?>">read&nbsp;more&nbsp;→</a>
                                            <?php $i++; ?>
                                        <?php endforeach; ?>
                                <?php endforeach; ?>
                            <!-- Page Pagination -->

                                <ul class="pagination pagination-lg">

                                    <?php if($pagination->hasPrevPage()): ?>
                                        <a href="<?php echo $pagination->prevPageURL() ?>">&larr;</a></li>
                                        <?php else: ?>
                                        <?php endif ?>
                                    <?php foreach($pagination->range(10) as $r): ?>
                                        <li><a<?php if($pagination->page() == $r) echo ' class="active"' ?> href="<?php echo $pagination->pageURL($r) ?>"><?php echo $r ?></a></li>
                                    <?php endforeach ?>

                                    <?php if($pagination->hasNextPage()): ?>
                                    <li class="last"><a href="<?php echo $pagination->nextPageURL() ?>">&rarr;</a></li>
                                    <?php else: ?>
                                    <li class="last"><span>&rarr;</span></li>
                                    <?php endif ?>

Does the Issue have something to do with calling the loop for the calendar plugin data within the events-list loop? Any advice much appreciated

The issue is this line:

$calendar = $page->children()->nth($i)->calendar()->yaml()

By using this line, you ignore pagination and manually get the nth child.
Instead, simply use the following:

$calendar = $item->calendar()->yaml()

The same applies to the other instances where you use nth().

Thank you so much! That was the last major issue i have with my site. This forum has been a great help. Learned a few things as well :slight_smile:

I’ve removed all the $i from this code now. Now i see there’s no need for it at all.

Hi David,

next time, instead of creating the same topic again, could you pls. just edit the original post or add something to it to push it up again, pls.? That would help to keep the forum tidy :slight_smile:, thank you.

1 Like