- This topic is empty.
October 23, 2010 at 10:26 am #30622
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.comOctober 23, 2010 at 12:46 pm #77637BobMember
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:October 23, 2010 at 2:04 pm #77639
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 :)October 24, 2010 at 9:16 am #77578
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.October 24, 2010 at 10:22 am #77579
Sorry. It seems like a caching plugin was causing some issues with that code. It works.October 24, 2010 at 10:40 am #77580
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.htmlOctober 24, 2010 at 12:28 pm #77581BobMember
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
- The forum ‘Other’ is closed to new topics and replies.