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) :)

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

  8. Alex Says:

    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!

  9. Daddy Says:

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

  10. Daddy Says:

    Nevermind. I got it to work. Thanks.

  11. rei Says:

    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

  12. Richard Maxwell Says:

    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/

Leave a Reply

Subscribe without commenting