Left and right arrow to browse pages

I have a Works page which contains listed Work subpages. The Work subpages have an arrow navigation. A left arrow is to call the previous Work subpage, a right arrow is to call the next one. Unfortunately, it does not work yet. It seems the pagination refers to the current Work subpage which has no children.

How can I make the arrow navgation of my Work subpages refer to the children of the parent Works page and flip through these? My code so far:

<?php
$works = page('works')->children()->paginate(1);
$pagination = $works->pagination();
?>

<?php if ($pagination->hasPages()): ?>
<nav class="pagination">
   <?php if ($pagination->hasNextPage()): ?>
   <a class="next" href="<?= $pagination->nextPageURL() ?>">←</a>
   <?php endif ?>
   <?php if ($pagination->hasPrevPage()): ?>
   <a class="prev" href="<?= $pagination->prevPageURL() ?>">β†’</a>
   <?php endif ?>
</nav>
<?php endif ?>

P.S. I built a Works collection. It replaces page('works')->children()-> with collection('works') :

<?php
    return function() {
        return page('works')
            ->children()
            ->listed();
};

To navigate between single pages, you don’t use pagination, but prevPage and nextPage navigation.

1 Like

Thank you very much! :upside_down_face: