Prev/next pagination by date

Hi all,

as you can see in the above picture, I have some example blog posts which are sorted by date.
However, the previous / next pagination on the respecive subpages uses the numbers for sorting.
So if I was on “4_postfour” (see screenshot) and wanted to click “previous” to land on the previously published post “1_postone”, I’d land on “3_postthree”.
How can I get my pagination to use the dates instead of the sorting in the file explorer? (This way the posts are in the correct order even if I were to change the publish date of one)

This is what my link looks like:
<?= $page->prevListed()->url() ?>

And this is my sorting for the overview page:
$entries = $page->children()->listed()->sortBy(function ($page) {return $page->date()->toDate();}, 'desc');

I hope it’s clear what my issue is.
Thanks so much!

You have to pass the sorted collection as parameter:

$entries = $page->siblings()->listed()->sortBy(function ($page) {return $page->date()->toDate();}, 'desc');

if( $page->hasPrevListed($entries) ) {
  echo $page->prevListed($entries)->url();
}

Thanks!