Skip to content
Discussion options

You must be logged in to vote

We wrote a custom tag for a similar feature. It figures out the sort order of the collection and fetches the prev/next entry. It works great for unique values like slug or title.

{{ prev = { sibling:previous } }}
  <a href="{{ url }}">Previous page: {{ title }}</a>
{{ /prev }}

{{ next = { sibling:next } }}
  <a href="{{ url }}">Next page: {{ title }}</a>
{{ /next }}
namespace App\Tags;

use Statamic\Facades\Entry as Entries;
use Statamic\Tags\Tags;

class Sibling extends Tags
{
    public function next()
    {
        return $this->sibling(true);
    }

    public function previous()
    {
        return $this->sibling(false);
    }

    protected function sibling(bool $next = true)
    …

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
3 replies
@cbreitigan
Comment options

@jasonvarga
Comment options

@cbreitigan
Comment options

Comment options

You must be logged in to vote
6 replies
@daun
Comment options

@cbreitigan
Comment options

@daun
Comment options

@cbreitigan
Comment options

@daun
Comment options

Answer selected by cbreitigan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants