Recent Posts

Purpose

This plugin displays a list of the most recent posts to your blog in a highly customisable way.

This is version 2.5.0 download latest version. It is compatible with WordPress 1.5–2.5.

The plugin has an options page which lets you change how the output is generated and displayed.

Installation Instructions

  1. If upgrading from a previous version, first deactivate the plugin via the Plugins page and delete the plugin folder from your server.
  2. Upload the plugin folder to your /wp-content/plugins/ directory. You will also need to install the Post-Plugin Library.
  3. Go to your admin Plugins page and activate Recent Posts.
  4. Put <?php recent_posts(); ?> at the place in your theme files where you want the list of similar posts to appear. Lorelle on WordPress has a good guide to modifying themes for plugins. If you are using a widget-ready theme the plugin can be placed from the widget admin page.
  5. Use the admin Settings|Recent Posts page to set all the available options. Alternatively, the options can be overridden by passing a parameter to the recent_posts template tag.

Usage and Options

The configuration page will help you to set up the plugin to your satisfaction.

If you also install the latest version of Plugin Output Cache the output of this plugin will be automatically cached for efficiency.

Note: If you find that your list of recent posts comes out backwards it is probably because you have MySQL version 4.1.21. That version of MySQL has a bug when a SELECT statement has both DISTINCT and ORDER BY clauses. The latest versions of the plugin (2.5+) avoid this MySQL bug.

Finally…

I look forward to your help in ironing out any issues and implementing any good ideas. The plugin settings page has an option to submit bug reports but general comments can be left below.

Frequently Asked Questions

  1. Rating: +0


    Positive


    Negative

    Is it possible to show the recent posts per category? Something like:
    CATEGORY:
    *recent post 1
    *recent post 2
    * and so on…
    CATEGORY 2:
    *recent post 1
    *recent post 2
    * and so on…

    Yes it is possible but only by calling Recent Posts a number of times which is inefficient (though caching helps). Try:

    
    recent_posts('included_cats=1');
    recent_posts('included_cats=2');
    ...
    

  2. Rating: +0


    Positive


    Negative

    I would like to know if there is any way to display the recent posts in 2-3 columns?

    One way is by fancy CSS/JavaScript… but you can get the result by calling recent_posts() 2-3 times. Let’s say you want 5 posts in each column so you set the limit to 5 in the settings screen. The first time, recent_posts() gets you the top 5 posts; recent_posts(’skip=5′) the next 5; and recent_posts(’skip=10′) the next.

  1. Rating: +0


    Positive


    Negative

    How do I get it so that {link} displays the date instead of the title? If i use the {date} template tag, it shows the date but no link.

    You need to use the output template to tell the plugin exactly what to display. For example, if you want a link where the visible text shows the date of posting you could try:

    
    <li><a href="{url}">{date}</a></li>
    
    

  2. Rating: +0


    Positive


    Negative

    How do I format the output of the {date} tag?

    The blog’s date format is used by default but you can change it by adding a format string. The Codex has a page on format strings. Let’s say you want the date to look like Sunday, January 14, 2007. The correct format string is ‘l, F j, Y’ so you would write

    {date:l, F j, Y}

  3. Rating: +0


    Positive


    Negative

    I don’t want my post plugin widget to show on the main page, just the single post page. Is that possible?

    Yes. The widgets now let you choose the condition under which they are visible. The condition can be set using any combination of WordPress Conditional Tags, e.g., ‘is_home()’, ‘is_category()’, or ‘is_page()’.

    In this case the right condition is ‘is_single()’.

  4. Rating: +0


    Positive


    Negative

    I’m trying to place the plugin output just after a single post but other plugins seem to get in there first. Any ideas?

    Some plugins automatically tack on their output to the end of a post’s content. The only way to get something in between is to hope that those plugins offer a way to turn off that kind of behaviour and let you explicitly place their output with a template tag. The good news is that most plugins are cooperative.

  5. Rating: +0


    Positive


    Negative

    I found a script that allows me to put thumbnail images [or anything else] with each post. I was wondering if there was a way to integrate that with this plugin?

    If the script stores the thumbnails in a custom field you can use the output template tag {custom} to display them. Try
    something like:

    
    <img src="{custom:thumbnail}" alt="{custom:thumbnail-alt}" />
    

    A similar thing can be done with many other plugins.

  6. Rating: +0


    Positive


    Negative

    I want to show the same plugin in two different places but with different output: can I?

    Yes. Decide on one of the output templates and other settings you need and set them up from the options pages. The other invocation of the plugin then gets called with passed parameters to get the different output.
    e.g., random_posts('limit=3&output_template={custom:another_field}')

  7. Rating: +0


    Positive


    Negative

    I want an output template tag to do xxxxxx. How do I invent one?

    You have two choices: a) modify the output_tags.php in the post-plugin-library; b) use the {php} tag.
    If you go down route (a) (which is actually very easy) please let me know the new tag and I’ll maybe include it in the next version. If you use the {php} tag do be careful not to start WWIII.

  8. Rating: +0


    Positive


    Negative

    I uninstalled one of your plugins and now my whole sidebar has disappeared. How do I get it back?

    You have probably forgotten to remove the code calling the plugin, e.g., recent_posts();.
    I find a good practice is to use something like:

    
    if (function_exists('recent_posts')) {
      recent_posts();
    }
    

    That way, if I ever deactivate a plugin temporarily the website doesn’t fall apart.

59 Comments Add your own

  • 1. Rob  |  March 17th, 2008 at 6:20 pm

    Version 2.5 b3 posted
  • 2. Sue  |  March 25th, 2008 at 2:12 am

    Hi Rob,
    I got this running right away, and would like to do just one thing, and that is indent the date by 2 spaces or align it with the link. How do I do that?
    Thanks!
    Sue

  • 3. Rob  |  March 25th, 2008 at 8:12 am

    Sue: I’m not clear what you mean. Which date? Which link? Could you show me what your output template is?
  • 4. Sue  |  March 26th, 2008 at 4:48 am

    Hi Rob,
    I am using this in my right sidebar in the area near the top entitled “Featured”. I have jury-rigged the date by using   to push it to the right 2 spaces but would like to affect that indentation using proper code with your plugin. Would I use a div code for that? I am using your date code in the plug in config with the post link.
    many thanks,
    Sue

  • 5. Rob  |  March 26th, 2008 at 7:51 am

    Sue: Looking at the source code on your page I notice an extra <ul> in the Featured section. You are probably placing one before the plugin call AND asking for one in the plugin output (the prefix setting). Get rid of one or the other and the output should behave like your other lists… if that is what you want!
  • 6. thomas  |  April 3rd, 2008 at 8:05 pm

    Updated my blog to WP 2.5 and after updating the Recent Posts plugin it only shows the message “Post-Plugin Library missing”.

    How can I fix this?

  • 7. thomas  |  April 3rd, 2008 at 8:06 pm

    Ah, sorry. Found out I have to install the post-plugin library plugin. I am really sorry.

  • 8. printer  |  April 4th, 2008 at 5:08 pm

    Thanks for this great plugin. Its pefect for the site I am building.
    I have a question though, I have this other plugin called “Post Thumb Revisited”. i want to put the thumbnails generated by this plugin to show up before my recent-posts titles in the sidebarwidget. I’m not sure what it is that I should put in the ‘ custum field’ .. i think it should be something like this: <li>{link}<img src="{custom:function get_thumb}"</li> but what can be the so called ‘custom field’? ‘function get_thumb’ does not work. an url to the folder does not work either. Any hints on this? Thanks!

  • 9. Rob  |  April 4th, 2008 at 6:02 pm

    printer: You have two options I think. One is to try out the {image} tag which might do what you want; the other is to use not {custom} — which only works if the other plugin stores things in custom fields — but {php} which will let you call the get_thumb function.
  • 10. online business blogger  |  April 5th, 2008 at 2:23 am

    Rob

    can this plugin RecentPost work with wordpress static pages? I have it working with posts but, of course, pages don’t have categories.
    forgive me for taking up your time with silly questions, guess I should RTFM

  • 11. Rob  |  April 5th, 2008 at 3:24 pm

    online business blogger: You can choose to have pages included or not.
  • 12. printer  |  April 7th, 2008 at 9:10 pm

    Thanks Rob, i tried what you said.. Both ways worked indeed. I like the php field option. to bad i can not get it to display the thumbnail fot the correct post.. only the first one. i will try some more.. thanks for the hint.

  • 13. Rob  |  April 7th, 2008 at 9:17 pm

    printer: You can imagine that the {php} tag has passed to it the $result variable — an object corresponding to each post with values named after the columns of $wpdb->posts. For example, $result->ID.
  • 14. printer  |  April 8th, 2008 at 12:11 am

    Rob, I understand what you mean. I think.. The get_thumb() tag needs a reference to the post. What I now have is {link} {php:get_thumb()} in my field input. It has to be somthing like {php:$wpdb->posts->$result->get_thumb()} then? I will try some tommorow. thanks

  • 15. Rob  |  April 8th, 2008 at 12:36 am

    printer: I’ve just been looking at how Post Thumb Revisited works. Unfortunately, it is set up to give a thumbnail from the current post which is why you have been getting the effect you have. It seems to me that you could use the {image} tag to do the same job. get_thumb() finds the first image in a post and returns a thumbnail of it; {image:0} does the same. You can also specify the size of the thumbnail by adding extra parameters, e.g., {image:0:96) for 96px square thumbs, or in general {image:0:width:height}.
  • 16. adspedia  |  April 8th, 2008 at 9:39 am

    Is it possible to show a area of recent blog posts to my website, thus outside the WP CMS?

  • 17. Rob  |  April 8th, 2008 at 9:49 am

    adspedia: To be honest I have never tried. I notice you visited from a forum page proposing an answer to that question. Have you tried it?
  • 18. Printer  |  April 8th, 2008 at 12:16 pm

    Rob, I understand. I tried it with the {image} tag. Unfortunately it looks like the image get scaled (when I set the settings to display the image smaller). And therefore it looks a little “pixelated” or whatever, instead of creating a real thumbnail of course. But I think I will leave it without an image-thumb in the recent-posts then. I found the ‘Post Thumb Revisited’ plugin a little hard to tweak and manage to my liking. So I will stay with the recent-posts plugin for now. Thanks.

  • 19. Rob  |  April 8th, 2008 at 12:39 pm

    Printer: I think my own plugin should also make real thumbnails instead of just setting the display size — the current situation is a stopgap. So sometime soon real thumbnails may appear.
  • 20. Printer  |  April 8th, 2008 at 6:58 pm

    That would be great Rob. I’m building an illustration blog where different authers will publish there work. A thumbnail would be a nice little extra within the recentposts list. I’m realy looking foreword to it.Thanks very mutch for all the help so far! Ill stay tuned.

  • 21. Rene  |  April 8th, 2008 at 10:27 pm

    Hi Rob,

    first of all: I like you’re plugin very much! And your ‘how to’ is very clear.

    One question: I’m using the {image} tag in the recent comments. The images show up indeed, but I want some extra space between the image and the text. Is that possible? And, if yes, how? Thanks for your attention in advance.

  • 22. Rene  |  April 8th, 2008 at 10:39 pm

    Oh… I’m sorry. I found the solution right after I posted my question. Quite simple after all. I just added

    #recent-posts img {
    margin: 0 5px 0 0;
    }

    to my stylesheet.

  • 23. Rob  |  April 8th, 2008 at 10:43 pm

    Rene: Great! CSS and the output templates make a very powerful and flexible combination.
  • 24. Kuri  |  April 10th, 2008 at 10:21 am

    Thanks for this plugin. However, upon installation, it seems the plugin isn’t picking up on the CSS for links styling? Any advice on what I should do here?

  • 25. Rob  |  April 10th, 2008 at 2:02 pm

    Kuri: I’ve just looked at the source of your page and I wonder what you are using for the output template? Maybe you could send me a bug report from the plugin’s setting/options page and it will tell me the details.
  • 26. Diwaker  |  April 10th, 2008 at 6:26 pm

    I recently upgraded the plugins (using the Wordpress auto upgrade mechanism). Everytime I upgrade your plugins (shared library, similar/recent posts, recent comments etc), I lose the corresponding widgets from my theme and I have to go back and re-enable them. Is this a known issue? Thanks for the great work!

  • 27. Rob  |  April 10th, 2008 at 9:22 pm

    Diwaker: I haven’t had reports of this before… It’s possibly because I tried a change in the registration of the widgets and then switched back. But it could be a real bug … I’ll keep my ears open.
  • 28. Jens  |  April 13th, 2008 at 11:19 am

    Hey!

    I have used your recent posts plugin for a while now and it has been working great! Today I used the wordpress upgrade plugin automatically-function to get the latest version, after this it also said i needed the post-plugin library, which i didn’t have before, and i installed it. The problem is, now it doesn work anymore, and i had to remove it from my first page where i used to have my recent posts listed.

    The problem was that when it came to fetch the posts, it just stopped and nothing showed, and also the loading of the rest of the page stopped. Do you know what the problem might be? Thanks! // Jens.

  • 29. Rob  |  April 13th, 2008 at 11:27 am

    Jens: First, just check that the old plugin folder has been removed and the new one is in place (with its name-change to ‘recent-posts-plugin’). Then try deactivating the recent posts plugin and reactivating it. That usually does the trick. If not get back to me.
  • 30. Jens  |  April 13th, 2008 at 11:44 am

    Hey, thanks for the quick reply! Unfortunately it doesn’t seem to work. It is in place, I tried to deactivate and activate again, but as you see on my first page, http://www.jensfilipsson.com, it doesn’t load up correctly. If you check http://www.jensfilipsson.com/blogg, i also have a footer that doesn’t load up on the first page. And of course, no recent posts there either.

  • 31. Rob  |  April 13th, 2008 at 12:24 pm

    Jens: Can you leave a bug report from the Recent Posts settings page? It will give me some more information to help debugging.
  • 32. Jens  |  April 13th, 2008 at 12:27 pm

    Done!

  • 33. Jens  |  April 13th, 2008 at 1:03 pm

    Hey, I just went to look at my widgets page, and instead of displaying the list of availible widgets and sidebars, it stops loading at the recent posts widgets, which looks like thiis:

    %BEG_OF_TITLE%Recent Posts%END_OF_TITLE%

    so I guess there’s something wrong with the code or something somewhere?

  • 34. Rob  |  April 13th, 2008 at 2:22 pm

    Jens: Looking at the bug report you just sent … I’m not seeing any options set. Either there’s something wrong with the bug report (possible) or you need to go to go to the settings page and set up some option values.

    Meanwhile I’ll look again at the Recent Posts code.

  • 35. Jens  |  April 13th, 2008 at 2:37 pm

    Hey!
    Unfortunately I have options set, they are the same as before I upgraded. And, the problem with the widget not loading correctly I would say suggests that something is wrong.

    I’m removing it from my front page now, so that the page can load normally, but I hope to be able to put it back soon, it’s a great plugin! :)

  • 36. Rob  |  April 13th, 2008 at 5:21 pm

    Jens: The problem was traced to the code that strips pseudo-tags from snippets. It is fixed in Post-Plugins Library 2.5b21.
  • 37. Ghost  |  April 16th, 2008 at 12:56 pm

    Hi there Rob,
    I don’t know how to use this plugin exactly. I’ve installed everything necesary and i’ve installed the Recent_posts plugin but i dont know how tu put it on the first page . I want to use this plugin to show the latest posts in one single post . For example , let’s say i’ve posted 5 posts recently . I want to show a list with the latest posts in one single post on the front page of my website I hope you understand what I want .

  • 38. Rob  |  April 16th, 2008 at 3:14 pm

    Ghost: I’m not exactly sure what you mean. Is your first page supposed to be blog-like or is it a static page? I mean is it what WordPress calls a page or a post?

    You have to insert a call to recent_posts() somewhere in your one of themes’ php files. But where depends on the answer to the questions I asked?

    Give me a clue and I’ll be glad to help.

  • 39. Ghost  |  April 16th, 2008 at 6:43 pm

    I think it’s more a static page . I want to have a list of the lastest 30 posts for example on the main page , in the center , like a post . I don’t want the Latest_posts plugin on the right or left , just in the center of my main page .

  • 40. Rob  |  April 17th, 2008 at 4:55 pm

    Ghost: You will need to create a page template to do this. It’s not hard to do but may be unfamiliar. When you create a static page in WordPress it is based on a template. The template contains code and defines where in the page the stuff you enter in the write screen goes. To include recent_posts() in a front page you need to make a copy of the page.php template file, edit it suitably, and then create a page based on it that will be your first page.

    For more information visit the codex: here, here, or here

    Good luck!

  • 41. Martin  |  April 18th, 2008 at 12:58 am

    Hi
    Fantastic plugin, lots of features. Well done !

    Quick question , I want to put the {categorylinks} at thetop of the links but it keeps repeating the {categorylinks} for each post link…. how can I get around this ?

    {categorylinks}
    {date: F j} | {link}

    This keeps repeating the category link above each category post. I just want one instance of the category link at the top.

    thanks
    Martin

  • 42. Rob  |  April 18th, 2008 at 9:35 am

    Martin: I’m sorry but you can’t do that within Recent Posts right now, though I’m considering adding the feature. You can, of course, put the category links before the call to recent_posts() in your theme file.
  • 43. Martin  |  April 18th, 2008 at 9:56 am

    Hi Rob

    Thanks for that. Ok , so what is the code syntax to put the category link before the call to recent_posts(). I had a look on the site here but coudnt find any examples.

    Thanks
    Martin

  • 44. Rob  |  April 18th, 2008 at 10:00 am

    Martin: Just an ordinary WordPress template tag. Probably
    <?php the_category(','); ?>.
  • 45. Martin  |  April 18th, 2008 at 10:47 am

    OK thanks Rob. That *worked* but I am using two instances of the recent posts on the same page and because its showing posts from two seperate categories, then it will only show the first category title on that page ….. unless I am missing something .

    thanks again
    Martin

  • 46. Rob  |  April 19th, 2008 at 10:08 am

    Martin: I’m not sure exactly what you are trying to do (sorry). The {categorylinks} tag ‘knows’ which links to show because it can look at the post it is currently displaying. You will need to duplicate that manually. If you know which category id you want to display you can use get_category_link() to get the category url which you would have to wrap in a hyperlink.

    If you look at the ‘otf_categorylinks’ function in ‘/post-plugin-lubrary/output_tags.php’ it will give you the idea.

  • 47. Arwen  |  April 19th, 2008 at 2:28 pm

    Hi Rob. Firstly I want to let you know that I really love your plug-in. I have a simple question, and the answer is probably right in front of my face, but I can’t for the life of me figure it out.

    I am building a theme for my site that uses the Recent Posts plugin to show a list of “updates” posts on my sidebar. All of these one-sentence posts will go in the “update” category in my WP. Now I’ve easily and quickly configured your plug-in so that it only shows the posts from the “update” category, but now how do I exclude those very same posts from my WP main page?

    Essentially, I don’t want them showing up as normal posts on my blog, I want them showing up on the “updates” section of the sidebar. I’m halfway there, I just need to figure out how to exclude them from showing up on the front of my blog when I post a new one.

    For example:

    The “snippets” on http://www.guitarangel.net

    or

    The “asides” on http://www.jemjabella.co.uk

  • 48. Rob  |  April 19th, 2008 at 4:06 pm

    Arwen: Your question then is really how do you exclude a category from the list of posts on your front page…

    Here are a couple of resources that should help. These, from the Codex and Perishable Press, seems right on the mark. The other, from the Codex, is more general.

    I hope these help!

  • 49. Arwen  |  April 19th, 2008 at 4:37 pm

    Thank you very much!

  • 50. Arwen  |  April 19th, 2008 at 4:48 pm

    Thanks… although they don’t really help with the new version of wordpress. They make references to category ID numbers, which I can’t find in the new wordpress admin panel.

  • 51. Rob  |  April 19th, 2008 at 5:24 pm

    Arwen: You might well find that the category slug works instead, though I am not sure. However, it is easy enough to find the category ID. Go to the Manage | Categories screen and hover over the name of the category you are interested in and the browser status bar should show it. If you have the status bar disabled click on the link and look in the address bar of the page you arrive at.

    Good Luck!

  • 52. Arwen  |  April 19th, 2008 at 5:25 pm

    Nevermind, I was able to figure it out. Thank you for the help!

  • 53. Blog Bloke  |  April 25th, 2008 at 8:33 am

    When I try to deactivate the plugin it blows apart my template right after section that I used your plugin. Any suggestions?

    …BB

  • 54. Lucas  |  May 13th, 2008 at 11:11 am

    I think its a great plugin, too bad it doesn’t have a feature to hide it from the frontpage, so its only visible when a single article is viewed! I do like the option that you can skip a number of posts!

  • 55. Lucas  |  May 13th, 2008 at 11:13 am

    Sorry, I found it!! Great plugin!

  • 56. Lucas  |  May 13th, 2008 at 11:52 am

    I would like to show Recent Posts on pages and single posts.

    So I use the option, is_single() on the widget page where it says ’show only if page’. Now the recent articles are not showed on pages.

    In the General Settings page there is an options ‘Show static pages?’. Setting this to ‘Both pages and posts?’ also shows pages on the recent posts list. And shoulds it only on single posts!

    In the widget page (’show only if page’.) I changed is_single() to is_single(),is_page() and is_single(),is_page(pagename) and to is_single();is_page() with a dot/comma. But the recent posts list is showed on the pages like this.

    How can this be done?

    Great help!

  • 57. Lucas  |  May 13th, 2008 at 11:54 am

    In the widget page (’show only if page’.) I changed is_single() to is_single(),is_page() and is_single(),is_page(pagename) and to is_single();is_page() with a dot/comma. But the recent posts list is NOT showed on pages like this.

    How can this be done?

  • 58. Rob  |  May 13th, 2008 at 2:28 pm

    Lucas: You are heading in the right direction. The condition in the widget settings has to be a valid PHP expression so it should be something like:

    is_single() || is_page()

    i.e., show if a single ‘page’ OR (’||’) a page ‘page’.

  • 59. Lucas  |  May 13th, 2008 at 11:26 pm

    Thanks, you are my person of the day!

Leave a Comment

Required

Required, hidden

Trackback this post  |  Subscribe to the comments via RSS Feed