🚀 A new era: Kirby 4 Get to know
Skip to content

Previous / Next navigation

These little snippets let you create a useful prev / next switcher navigation for your pages.

<?php if ($page->hasPrevListed()): ?>
<a href="<?= $page->prevListed()->url() ?>">previous page</a>
<?php endif ?>

<?php if ($page->hasNextListed()): ?>
<a href="<?= $page->nextListed()->url() ?>">next page</a>
<?php endif ?>
<?php if ($page->hasPrevUnlisted()): ?>
<a href="<?= $page->prevUnlisted()->url() ?>">previous page</a>
<?php endif ?>

<?php if($page->hasNextUnlisted()): ?>
<a href="<?= $page->nextUnlisted()->url() ?>">next page</a>
<?php endif ?>
<?php if ($page->hasPrev()): ?>
<a href="<?= $page->prev()->url() ?>">previous page</a>
<?php endif ?>

<?php if ($page->hasNext()): ?>
<a href="<?= $page->next()->url() ?>">next page</a>
<?php endif ?>

If you flip the sorting of your pages, for example in a list of blog articles, you might also need to reverse the logic of the prev and next links to make sense.

Author