scriptygoddess

04 Dec, 2007

Next Previous Posts in Same Category

Posted by: Jennifer In: WordPress Plugins

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

13 Responses to "Next Previous Posts in Same Category"

1 | scriptygoddess » Blog Archive » Next/Previous posts in same category

December 4th, 2007 at 1:38 pm

Avatar

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

January 17th, 2008 at 5:33 pm

Avatar

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

February 7th, 2008 at 9:41 am

Avatar

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

March 9th, 2008 at 2:46 pm

Avatar

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

March 9th, 2008 at 9:40 pm

Avatar

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

April 14th, 2008 at 1:55 pm

Avatar

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

7 | Jay

April 20th, 2008 at 1:20 pm

Avatar

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

May 24th, 2008 at 3:47 am

Avatar

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

June 30th, 2008 at 8:41 am

Avatar

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

June 30th, 2008 at 8:51 am

Avatar

Nevermind. I got it to work. Thanks.

11 | rei

July 9th, 2008 at 12:38 pm

Avatar

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

August 19th, 2008 at 5:16 pm

Avatar

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/

13 | Richard

September 12th, 2008 at 2:14 am

Avatar

Sorry to jump into these comments slightly off-topic, but I dearly miss your wpPaginate plugin. Has it been updated in recent years?

I would LOVE it to work in 2.6, 2.7 >>>>

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements