Traverse posts of the same tag with `prev_post` & `next_post`

Is it possible for prev_post & next_post to traverse posts with the same primary tag?

I have a collection for photos with a custom template. I would like to setup previous and next buttons to browse images. At the moment, it also navigates to other non-photo-tagged posts.

Yep, it’s documented here:


Should have scrolled! Thanks Hannah!

Adding the in attribute doesn’t seem to work. Other posts still appear while traversing.

I’ve checked that the posts really do have a primary tag.

It should be noted that the posts are in a collection which filters for the same tag.

    template: photos
    permalink: /photos/{id}/
    filter: tag:photos
1 Like

I have the same issue on collections. The next_post and prev_post helper traverses correctly the primary without taking care of the collection.

Is there a way to traverse a random tag? (not only the primary tag) It would be useful for multilingual content blog too.

1 Like