Some time ago, I used the following code to switch between page children:
<ul>
<?php if ($page->hasPrevListed()): ?>
<li><a href="<?= $page->prevListed()->url() ?>">←</a></li>
<?php else: ?>
<li><span>←</span></li>
<?php endif ?>
<?php if ($page->hasNextListed()): ?>
<li><a href="<?= $page->nextListed()->url() ?>">→</a></li>
<?php else: ?>
<li><span>→</span></li>
<?php endif ?>
</ul>
Now, I want switch site children of a specific template but the filtering does not work.
<?php if ($site->children()->filterBy('template', 'work')->listed()->count() > 1): ?>
<ul>
<li><a href="<?= $page->prevListed()->filterBy('template', 'work')->url() ?>">←</a></li>
<li><a href="<?= $page->hasNextListed()->filterBy('template', 'work')->url() ?>">→</a></li>
</ul>
<?php endif ?>
May I use this function: $page->hasTemplate(): bool? Or do I have to work with variables? I would like to loop thourgh the pages. Last page to first page and vice versa.