I’m trying to create links to the next and previous posts within a specific tag (on the post page itself), but I can’t seem to find a plugin or source that does this.
I want to be able to something like this, appearing below the post.
get_previous_link("tagname");
get_next_link("tagname");
Anybody know of a way to accomplish this? Otherwise I’ll have to write something myself, which is fine, but I figured I wouldn’t reinvent the wheel unless I have to.
get_adjacent_post()
, which is used by all functions that return a (link to) the next or previous post, only has a$in_same_cat
argument, which looks at the categories the post is in, not the tags.You could hook into the
get_[next|previous]_post_join
to modify the join query for your call, but then it’s probably easier to copy the function, remove the category-specific code and replace it with tag-specific code. Or make it even more generic and submit it as a patch to WordPress 🙂Does this work for that problem? http://digwp.com/2010/04/post-navigation-outside-loop/
The code in that post works for “Archive-View Pages” & “Single-View Pages” 😛
Here’s a version of the copy/paste edit that @Jan Fabry alluded to above (definitely not the most elegant solution, but it should work):