Get Next or Previous Post with same Tag? (5 posts)

  1. not2bug
    Posted 7 years ago #


    I currently have a photoblog "Theme: Reflections http://photoblog.xyloid.org/reflection/" which displays each entry as a single post containing one image. I have tweaked archive.php so that I can display thumbnails with links for all images in either a relevant category or tag

    The problem lies in that once I view a particular post tagged as (lets say) 'XYZ', how do I query the next post or previous post links which have the same tag 'XYZ'?

    For categories, I can use get_next_post(true) or get_previous_post(true) to get the next and previous post in the same category however there isn't any direct implementation for doing this with tags.

    Could someone point me in the right direction for implementing this? I really can't figure out what functions I might have to play with so as to get the next and previous post under the current tag.


  2. MichaelH
    Posted 7 years ago #

    I don't see a way to do that, might have to resort to a plugin. Possibly something like http://wordpress.org/extend/plugins/in-series/

    The function get_adjacent_post is used to find the previous/next post in a category. Guess you could use that if you wanted to 'roll your own' function for tags.

    This also might be a reasonable report to make to Trac to make get_adjacent_post to honor all taxonomy types, especially since much work has been completed so support custom taxonomies.

  3. not2bug
    Posted 7 years ago #

    Thanks Michael,

    Looks like it is going to be pretty complicated to try implementing this. For now I'll stick with category based browsing. I know that another theme (Grain) for a WordPress photoblog manages to do this but it has tons of custom functions and php files.

    I'd try and do it myself but as much as I love coding, I stopped learning after QBASIC and some basic C =). I'm quite with the amount of hacking I've managed so far just by understanding the code logic and familiarizing myself with syntax. Thanks again. Hopefully this will be something that is easier to do further down the road.


  4. MichaelH
    Posted 7 years ago #

    Reported request to make get_adjacent_post able to support all taxonomies.


  5. paperflame
    Posted 6 years ago #

    Ok Guys and Gals.. I searched and searched for a solution... BAM... found a solution.

    I am pretty sure this is what is trying to be accomplished. I stumbled on this thread about previous and next post in category.

    Check this plug-in out! It takes it a step further than just categories - it handles - tag, date, author, search etc. It uses a referrer.. Awesome....
    You can see it in action on my site http://www.paperflame.com/content


    Hope this helps if you didn't know about it!

Topic Closed

This topic has been closed to new replies.

About this Topic