Skip to content

Kirby 5.4.4

$page->prev()

Returns the previous item in the collection if available

$page->prev(Kirby\Cms\Pages|null $collection = null): Kirby\Cms\Page|null

Parameters

Name Type Default
$collection Kirby\Cms\Pagesornull null

Return types

Kirby\Cms\Pageornull

This method does not modify the existing $page object but returns a new object with the changes applied. Learn more →

Parent class

Kirby\Cms\Page

Examples

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

With collection as argument

By default, this method uses the page's siblings collection. Collection operations such as sorting, filtering, adding or merging return a new collection and don't change the page's sibling context. Pass the resulting collection to get the previous page in that specific collection.

<?php
$collection = $page->siblings()->listed()->sortBy('date', 'desc');
if ($prev = $page->prev($collection)): ?>
<a href="<?= $prev->url() ?>">previous page</a>
<?php endif ?>