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('&laquo; %link', 'Previous post in category: %title', TRUE); ?>
<?php next_post_link('%link &raquo;', 'Next post in category: %title', TRUE); ?>

Where the first argument (where I have “&laquo; %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) :)

7 Responses to “Next Previous Posts in Same Category”

  1. scriptygoddess » Blog Archive » Next/Previous posts in same category Says:

    [...] 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 [...]

  2. Link Love # 9 : SEO , Buzz, Blogging, Windows Tools, WordPress & Blogspot Tips » Tech At Hand Says:

    [...] 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. [...]

  3. Brian Says:

    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!!

  4. Rob Stur Says:

    What if a post is in multiple categories? Which one will it go to and how can you control which one it goes to?

  5. Jennifer Says:

    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..

  6. Richard Says:

    A long shot … any idea if it can be made to work on category children?

  7. Jay Says:

    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.

Leave a Reply