Skip to content

Kirby 3.6.6

$page->prev()

Returns the previous item in the collection if available

$page->prev(\Kirby\Cms\Collection|null $collection = null): Kirby\Cms\Model|null

Parameters

Name Type Default
$collection Kirby\Cms\Collection|null null

Return type

Kirby\Cms\Model|null

Parent class

Kirby\Cms\Page

Example

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

With collection as argument

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