Next Previous Posts in Same Category
I’ve gotten a few emails about my (old) Next/Previous Post in Same Category plugin and about the fact that’s its broken - however, this functionality is now built into wordpress. (and I have it working on the site right now as a matter of fact). I’m a bit behind on what has been included with each new version of Wordpress, so I’m not sure when this made it’s way in there, but.. YAY! Now I don’t have to update the plugin! LOL! So, in any case, if you want to include links to the next/previous post in the same category as the one being viewed, you just need to do this (on the “single.php” template page INSIDE the “Loop“)
<?php previous_post_link('« %link', 'Previous post in category: %title', TRUE); ?>
<?php next_post_link('%link »', 'Next post in category: %title', TRUE); ?>
Where the first argument (where I have “« %link”) is the format of what is displayed… ie. if you want text before or a tag around the actual link (represented by “%link”) this is where you say how you want it to show.
And the second argument (where I have “Previous post in category: %title” is the text of the actual link. You don’t have to have the “%title” in there - but I think it’s useful)
December 4th, 2007 at 1:38 pm
[...] ver 2.3.1). However - it is also no longer needed as this functionality is now part of Wordpress. Please see this post for more details. I will leave this post up here for the sake of archives, etc. but it is no longer [...]
January 17th, 2008 at 5:33 pm
[...] scriptygoddess teach us how to insert Next and Previous post in the category in which you can see at the bottom part of my blog post. [...]
February 7th, 2008 at 9:41 am
Hi Thanks for the heads up
i was wondering if there’s a way to do it for pages too?
thx in advance for the info!!
March 9th, 2008 at 2:46 pm
What if a post is in multiple categories? Which one will it go to and how can you control which one it goes to?
March 9th, 2008 at 9:40 pm
Hmm… good question. AFAIK its just showing next/previous on one category - but how it decides which one (and how to get it to show the others)… not sure..
April 14th, 2008 at 1:55 pm
A long shot … any idea if it can be made to work on category children?
April 20th, 2008 at 1:20 pm
Thanks for posting this. I wouldn’t know it is already in the codex if not for your post. Is there a way to add the post excerpt right below the title? TIA.
May 24th, 2008 at 3:47 am
Hello, and thank you very much for this great resource you’ve made available to us internet mortals.
I’ve implemented this behaviour on a recent blog using your advice, but I’d be very interested to know if it’s possible to do the same thing with posts by author.
I kind of answered my own question but not completely with this one here:
http://www.dagondesign.com/articles/posts-by-author-plugin-for-wordpress/
It’s maybe impossible to have posts by category and posts by author on the same page using the same template. Is it possible to have multiple single.php templates? Dunno, so many questions. Anyway, thank you and best wishes!
June 30th, 2008 at 8:41 am
Does this work in 2.5.x? Cuz I can’t seem to get it to work for me. When I replace the stock previous_post_link and next_post_link code with the code above, the “previous” and “next” links disappear altogether.
June 30th, 2008 at 8:51 am
Nevermind. I got it to work. Thanks.
July 9th, 2008 at 12:38 pm
Any idea how I would implement this if on the home page of my blog, I wanted to create a link to the most recent post of a certain category, then have the next/previous post links on all subsequent pages? TIA
-Rei
August 19th, 2008 at 5:16 pm
Hey There.
I used this plugin for my blog for over 2 years. But when I upgraded to wordpress 2.6.1 it all broke.
So I fixed it.
I have completly gutted the script and rewrote it to work with wordpress 2.6.1. Its the same interface - but with some addition tweaks.
you can find it here:
http://geriandricky.maxwells.net.nz/2008/08/20/next-previous-posts-in-same-category/