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

#1

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.

#2

Yep, it’s documented here:

1 Like
#3

Should have scrolled! Thanks Hannah!

#4

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.

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

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.