Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other [SOLVED] WORDPRESS – next_post_link() in category doesn’t seem to work

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #30622
    jheinrichs79
    Member

    I have been banging my head against the wall trying to figure out how to use next_post_link() in WordPress so that if I click on a category and then hit the “Next Link” it will take me to the next post in that category instead of the next post based on date which most likely isn’t from the same category.

    I’ve done some searching and everyone says to use tags but unfortunately the site has been around for a while and I have created a very structured menu structure around categories.

    I havne’t found an answer in the Book Digging into WordPress either.

    I am most likely thinking that I’d have to create my own new function but have no clue on where to start or how to do it.
    If it makes things any easier I don’t think I’d ever need “The next post based on date” for next_post_link(). I’d always want to use it for displaying the next post in the category.

    Any help would be really appreciated!

    If you need to look at the website it is located at: jaredheinrichs.com

    #77637
    Bob
    Member

    With the next_post_link() function, you can set it so that it will only display posts from the same category, by setting the third parameter to TRUE, like here:

     
    #77639
    jheinrichs79
    Member

    Thanks I will try it and let you know if that works. If it does if you’re ever in Winnipeg I’ll buy you a beer :)

    #77578
    jheinrichs79
    Member

    I just tried the suggestion and it and it doesn’t seem to work. I am wanting this functionality on the single.php page. I’m thinking the only way this could be done is by creating a new method in function.php and editing the default way next/previous post link works. So what I am looking for doesn’t matter what post a person is on, all Posts will have a category linked to them. I want the person to be able to click on the next post/previous post at the bottom of the post and be taken to the next/previous post in the same category not the next post by date. Any other ideas? I’ve left the last suggestion in place on the site: http://jaredheinrichs.com/how-to-create-and-remove-html-elements-using-jquery.html This is in the category of jQuery.

    #77579
    jheinrichs79
    Member

    Sorry. It seems like a caching plugin was causing some issues with that code. It works.

    #77580
    jheinrichs79
    Member

    I’ve written an example on my blog about this since there doesn’t seem to be too much info online. I credited you with the answer. http://jaredheinrichs.com/wordpress-next_post_link-to-next-post-in-category.html

    #77581
    Bob
    Member

    Thats very kind of you! However, the real credit ofcourse goes to the wordpress codex, which is where I got it from :) http://codex.wordpress.org/Function_Reference/next_post_link

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Other’ is closed to new topics and replies.