[WP Plugin] Prev and Next ‘n’ Posts

728 Views Sun, 04 Feb 2007 at 03:27 pm

For easier navigation, I want to put the link to previous and next 3 posts relative to the current post. The built in functions within WordPress are capable of showing the adjacent previous post ( previous_post_link() ) and next post ( next_post_link() ) only.

Googling, I found the Previous Posts (recently it was updated to work on WP 2.1) plugin by Sadish Balasubramanian. Still, it can only produce previous ‘n’ posts, and not the next ‘n’. So, it’s time to look at the code … )

Modifying WP Plugins turned out to be not a very difficult task (mind you, I’ve only used Wordpress for less than a month). For greater flexibility, I modify the original get_previous_posts function so that it returns a false when no posts are found (instead of a string “No more previous posts” ) , then I add the get_next_n_posts function that will search for the ‘n’ next posts relative to the current post (basically, the only modification is to the mysql query).

So here it is, my first plugin: Prev and Next ‘n’ Posts. I used it in my blog (look at the Post Navi on the right) running WP 2.1. I don’t have enough resources to test it with previous WP versions, give me a shout if it doesn’t work.

Download it here.

To use it, just unzip the file into your plugin directory and then activate it. Two functions are added by this plugin: get_previous_n_posts and get_next_n_posts.

Here is how I used the functions in my sidebar.php file:

Error: Could not open prev_next_n_post_sidebar_example.php

Please leave comments if you need help (time permit, I will try as best as possible to help you).


This entry was posted in category: tips.
Last modification was on Sunday, 19 Aug 2007 at 05:57 pm

1 Comment »

#1 phimagery's comment on Sun, Aug 19, 2007 at 08:55 am #
Very intersting, but the files are not downloadable.

Leave a comment

roll yes o ) ) =( p no =| love lol grinnod d 8) x

  

RSS feed for comments on this post. TrackBack URI