I've seen a few people request the ability to do next/previous posts within the same category. I thought it had already been done and I swear I looked around to see if anyone had, but I didn't find it. If it has been done, well at least I had fun writing this.
Current Version: v 0.2
Last updated: 10/04/04 8:51pm
So here's my next/previous post in category plugin:
1) Download and install this plugin (right-click save as.. with a .php extension) – upload to your wordpress plugins folder (wp-content/plugins/ ). Activate through the admin interface.
IMPORTANT NOTE ABOUT DOWNLOAD: Make sure you do NOT have any extra spaces after the last ?> in your copy of the file. Extra spaces will give you various "header already sent" type errors.
2) This plugin has two functions:
previous_cat_post();
next_cat_post();
To use the plugin functions you can simply call them where you want the next and previous links displayed (but they must be called from within the wp loop). The default display will look like this:
- Previous post in CategoryName:
Post name - Previous post in anotherCategoryName:
Another Post Name
- Next post in CategoryName:
Another Post
Of course you can customize it.
3) Each function has the following parameters you can pass to it:
$beforeGroup (string) text/html to be displayed before the list of categories and posts. Default is '<ul>'.
$afterGroup (string) text/html to be displayed after the list of categories and posts. Default is '</ul>'.
$beforeEach (string) text/html to be displayed before each category/post. Default is '<li>'.
$afterEach (string) text/html to be displayed after each category/posts Default is '</li>'.
$showtitle (true | false) true if you want to include the title of the post in the link (see below for how this looks if set to false). Default is true.
$textForEach (string) text/html to be displayed with each line. If $showtitle is set to false – this line becomes the link. If $showtitle is true – this line will be displayed before the title (which will be link). This differs from $beforeEach in that you can have it dynamically display the category name. Where you want the category name to display – put a %. Default for previous_cat_post is 'Previous post in %:<br />'. Default for next_cat_post is 'Next post in %:<br />'.
So some sample uses:
previous_cat_post($beforeGroup='<p>Previous Posts within categories</p>', $afterGroup=", $beforeEach='<p>- ', $afterEach='</p>', $showtitle=false, $textForEach='Previous post in %');
Would display this:
Previous Posts within categories
– Previous post in CategoryName
– Previous post in Different CategoryName
(notice that here, since we set $showtitle to false, the $textForEach becomes the link without showing the title of the post.)
Change Log
New in ver 0.2
Links that are generated now make use of the customized permalink structure.
Supports up2date plugin.
New in ver 0.1.2
Fixed a minor bug relating to double-quotes in titles.