My pagination isn’t quite working. there are only 4 events and pagination is set to 3 per page. when i load the second page it loads the first event again on it’s own instead of the the last post.
My code is below. I used the kirby docs pagination structure. I’m pretty sure it’s not working because of the loop inside of my events loop but i have no idea how to correct it.
<div id="main-container">
<div class="content">
<div class="container">
<div class="row">
<div class="col-md-12 content-block">
<ul class="events-list">
<?php $events = $page->children()->paginate(3);
$i = -1;
foreach($events as $event) {
$i++; ?>
<li class="event-list-item">
<?php $calendar = page('events')->children()->nth($i)->calendar()->yaml();
foreach($calendar as $calendarEntry) { ?>
<span class="event-date">
<span class="date">
<?php
$eventday=strtotime($calendarEntry['_begin_date']);
echo date('j',$eventday);
?>
</span>
<span class="month">
<?php
$eventmonth=strtotime($calendarEntry['_begin_date']);
echo date('M',$eventmonth);
?>
</span>
<span class="year">
<?php
$eventmonth=strtotime($calendarEntry['_begin_date']);
echo date('Y',$eventmonth);
?>
</span>
</span>
<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>
<p>
<?php echo page('events')->children()->nth($i)->eventwriteup()->excerpt(250); ?> <a href="<?php echo page('events')->children()->nth($i)->url(); ?>">read more →</a>
</p>
<!-- <a href="#" class="btn btn-default">Book Tickets</a> -->
</div>
<?php } ?>
</li>
<?php } ?>
</ul>
<!-- Page Pagination -->
<?php
$list = $page->children()->paginate(3);
$pagination = $list->pagination();
?>
<nav>
<ul class="pagination pagination-lg">
<?php if($pagination->hasPrevPage()): ?>
<li>
<a href="<?php echo $pagination->prevPageURL() ?>">←</a></li>
<?php else: ?>
<li><span>←</span></li>
<?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() ?>">→</a></li>
<?php else: ?>
<li class="last"><span>→</span></li>
<?php endif ?>
</ul>
</nav> ....