Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

How to: Limit Post navigation to posts with the same tag?

  • #9570
    Avatar photo[anonymous]

    Say I have a site with the following posts:

    Comic page 1  [tags: Comic]

    Comic page 2 [tags: Comic]

    Comic page 3 [tags: Comic]

    Home page [tags: None]
    About Page [tags: None]

    Sketchbook page 1 [tags: Sketch]

    Sketchbook page 2 [tags: Sketch]

    Sketchbook page 3 [tags: Sketch]

    If someone is on a comic page, I only want the navigation to go to previous and next comic posts.
    If someone is on a sketch page, I only want the navigation to go to previous and next sketch post.

    Thus far my only solution idea I’ve come up with is to use separate “sites” for each tag I want to have it’s own navigation.

    #9572
    Avatar photo[anonymous]

    You can create your own Handlebars helpers. Take a look at the example here. In your case I think you’d do something like this:

    • have a `prevForTag` helper and a `nextForTag` helper;
    • have each helper take a tag, a post, and the list of posts;
    • find the current post in the list; and
    • scan backwards or forwards looking for the previous or next post with the given tag.

    Maybe not exactly that, but maybe something like that.

    #9590
    Avatar photo[anonymous]

    Hey, I actually had the same question a few years ago. 🙂

    Here is the thread: https://forum.getpublii.com/topic/filtering-post-navigation-nextpost-and-previouspost-by-tag/