Recent Posts

Caveat

Unfortunately, due to ill-health, this plugin has not been developed or supported properly for some years. It works with the latest versions of WordPress (including on this website) but could possibly conflict with any WordPress features added after 2008 — e.g. custom post types — if you use them.

Purpose

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

This is version 2.6.2.0 download latest version. It is compatible with WordPress 1.5–2.6.2.

  • 2.6.2.0 supplies a .pot file making internationalisation possible; introduces the {imagealt} output tag and allows {excerpt} to output whole sentences; the content filter and the widget can now take a parameter string; output can be automatically placed after post content without editing theme files.
  • 2.6.1.0 allows the current post to be marked manually where the automatic mechanism fails; when used as a widget the plugin now honours the setting to show nothing when there is no output; and {commenterlink} now applies the appropriate WordPress filter.
  • 2.6.0.1 fixes the option to include attachments and adds a parameter to the {imagesrc} output tag to append a suffix to the image name.
  • 2.5.0.11 has a new option to include posts which are attachments; a new output template tag {authorurl} which points to the archive of the author’s posts; new behaviour for the {php} output tag which can now accept other output tags in the code.
  • 2.5.0.10 fixes several bugs.
  • 2.5.0.9 adds options to match the current post’s author and to select posts by date of last modification rather than date of creation. Also extends the options for snippet and excerpt output tags to make the ‘more’ text into a link.
  • 2.5.0.8 adds an option to show posts by status, i.e., published/private/draft/future, changes the {categorynames} and {categorylinks} output tags by applying the ‘single_cat_name’ filter, and fixes a bug in WordPress pre-2.2 that stopped installation code running on Windows servers.
  • 2.5.0 introduces a new output tag {imagesrc}, and adds more parameters to {image}. Fixes bugs with empty categories, excluded posts, and the option to omit current posts.
  • 2.5b25 makes some important changes: the {image} output tag now serves real thumbnails (couple of bug fixes too); output can now be sorted as you choose with sub-headings included; the {date:raw} tag modifier has been added to help the sorting; the ‘trim_before’ option has been replaced with the more logical ‘divider’.
  • 2.5b24 fixes to stop recursive replacement by content filter, {gravatar} to allow for ‘identicon’ etc., to {commenter} to allow trimming, and to remove a warning in safe mode
  • 2.5b23 brings a new option to filter on custom fields and adds proper nesting of braces in {if}.
  • 2.5b22 fixes bugs in several output tags, and introduces the option to show only pages.
  • 2.5b18 fixes filtering output and introduces the conditional tag, (if:condition:yes:no}.
  • 2.5b16 fixes a problem with {php}.
  • 2.5b15 more bug fixes and added ‘included posts’ setting.
  • 2.5b14 continuing bug fixes.
  • 2.5b11 has new features and improvements.
  • 2.3.6 restores the widgetiness I managed to remove in 2.3.5!
  • 2.3.5 has been rebuilt to save memory and can match the current post’s tags. It also fixes a bug with categories in WordPress < 2.3.
  • 2.3.4 now works as a widget. Also can include or exclude the current post from the output.
  • 2.3.3 beta adds the ability to include as well as exclude categories and authors and is able to find posts by tag.
  • 2.3.2 beta fixes a conflict between tags and categories.

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.

238 replies on “Recent Posts”

  1. Craig: I hate it when one plugin developer says the problem is with another developers plugin… so I won’t do that. But the error message happens when Ozh’s plugin tries to set cookies after the page has already sent headers. Maybe that’s something to do with your page not being ‘WP-driven’. (BTW how do you get Recent Posts working if the page is static, non-WP?)

  2. crap — no PHP… um… maybe with the code tag:

    
    <?php require_once("/home/useracct/public_html/wordpress/wp-config.php"); ?>
    
    <?php echo recent_posts(); ?>
    

  3. Craig: I wonder if that unnescessary ‘echo’ might not be the root of the problem? Try removing it (the plugin echoes automatically) and see if the header problem vanishes.

  4. Hi, Rob. Great Plugin. Thank you for your good work.
    Here is my problem: in my first (main) page i want ‘recent posts’ to show me the next 8 posts (i have 8 per page) so people will have an idea of my previous posts in page 2. Everything works OK, but when i go to previous page (page 2), it shows me the same first posts instead of showing me the next (or previous) posts of page 3. Am i doing something wrong? Thanks in advance.

  5. Marco: You’re not doing anything wrong — the plugin doesn’t support that kind of behaviour … but it sounds like a very good idea. I’ll see if I can implement it. Thanks.

  6. Thank you for you quick reply. I am sure lots of people would like to see this behaviour included in future versions – i know i would! Nevertheless, all i can say is thank you for your good job and effort.

  7. Awesome plugin, I love it.

    A quick question – under the filtering options, is there any way to filter out posts which do not have a title? I am thinking it could somehow be done with the custom filter option, but I have been unsuccessful in figuring out how…

  8. Michael Jones: As it stands there is no easy way to catch posts the way you want. You could filter on a custom field if you had one already set up for posts which have no title but that sounds messy.

  9. Marco: I think the best way of doing what you want is to replace the call to recent_posts in your template with a bit of dynamic code that works out the parameters you want on each page.

    So, instead of

    <?php recent_posts(); ?>

    use

    <?php 
    	$ppl_page = $GLOBALS['wp_the_query']->query_vars['paged'];
    	if (!ppl_page) $ppl_page = 1;
    	$ppl_limit = $GLOBALS['wp_the_query']->query_vars['posts_per_page'];
    	$ppl_offset = $ppl_page * $ppl_limit;
    	recent_posts("skip=$ppl_offset&limit=$ppl_limit"); 
    ?>

    Of course this won’t work if you are using the less flexible widget. Let me know if it works for you.

  10. Rob, thank you for your quick reply and your code. Almost worked!
    Now what’s happening is this: first page shows the very same posts of the first page: not working.
    From page 2 , etc, it’s working as you expected, showing the next 8 posts of next pages and so on.
    You can see it already in (experimental) action in my blog, Portuguese language only, sorry.

  11. Marco: You found the deliberate mistake! There’s a ‘$’ missing in the code:

    if (!ppl_page) $ppl_page = 1;

    should be

    if (!$ppl_page) $ppl_page = 1;

  12. Hey, this is great plugin. Thank you. πŸ™‚

    I used your “recent post” plugin to my posts, for including “5 related post” in each post based on their tag. My suggestion is, my be you should add an “date option”, so we can including “related post in the past”, not only “related post” like usually. Thank you.

    NB: Sorry if my english is bad, because I’m novice in english language, I’m an Indonesia.

  13. Hendra: Thanks for the kind words! In fact you can already filter the output so that only posts older (or younger) than n days/months/years appear.

  14. Thank Rob, for your respons.

    About my suggestion, what I mean is: we can embed “related post in the past” on each post. “in the past” here means: based on “current post” date. So, if there is a post with published date: 4 Apr 2008 5:00 PM, then the related post is only displaying any post with published date: before 4 Apr 2008 5:00 PM.

  15. Hendra: I see what you mean. It is on the wish list now.

    If you don’t post many times in a day you can approximate that effect this way:

    
    <?php 
    $post_days = floor((time() - strtotime($post->post_date)) / (60*60*24)) + 1;
    recent_posts("age-direction=before&age-duration=day&age-length=$post_days");	
    ?>
    

  16. Is it also possible to add for every new day 1 time above the recent post wich day the articles are posted?

    so that you get this:

    Date (today)
    article 1
    article 2
    article 3
    article 4

    Date (yesterday)
    article 1
    article 2
    article 3

    Date (day before yesterday)
    article 1
    article 2
    etc
    etc

  17. Rool: The output from Recent Posts doesn’t really have a width as such — it just emits what you tell it to in the output template. How that displays is all up to your CSS.

    For the grouped output make some entries on output settings screen: sort by {date:Y-m-d} descending and use {date} as the group output template. You can use whatever you like as the output template for the article items, e.g., <li>{link}</li>

    Good luck!

  18. Hi Rob,

    I use your “Random Post” and the “Recent Post” plugin. Both working fine, but I have a output problem with “Recent Posts”. To display different graphics for each category I use a similar code like that:

    It works fine for the Random Post plugin with 6 categories but if I use {categoryid} with the Recent Post plugin it just return two different category numbers.

    Also is it possible to have a kind of navigation for the Recent Post plugin. I want to show 5 recent posts per page but with the possibility to go further back in the archive. So basically the functionality what you can get with the index.php

    Thanks for your help
    Alfons

  19. Hmm…the html code didn’t show up….I’ll try it again:

    div id=”postHeader{categoryid}”
    div class=”post{categoryid}”

  20. Alfons: Let me work backwards… I answered above what might be a similar question about using Recent Posts to give a glimpse of older posts. I suggested the following code which you might be able to adapt:

    
    <?php 
    	$ppl_page = $GLOBALS['wp_the_query']->query_vars['paged'];
    	if (!$ppl_page) $ppl_page = 1;
    	$ppl_limit = $GLOBALS['wp_the_query']->query_vars['posts_per_page'];
    	$ppl_offset = $ppl_page * $ppl_limit;
    	recent_posts("skip=$ppl_offset&limit=$ppl_limit"); 
    ?>
    

    Basically the code works out the range of posts you want to display and passes that information to the plugin as a parameter string.

    Now for the {categoryid} issue. It is hard to see why Random Posts and Recent Posts should behave differently since the code to evaluate {categoryid} should be from the same file — post-plugin-library/output_tags.php. It’s possible there is a bug in the common code though.

    {categoryid} is an awkward tag! Since categories can be hierarchical and since posts can belong to multiple categories, certain decisions have to be made. I work on the following rules: 1) if multiple categories are assigned to a post the more general ones are knocked out if more specific ones are also assigned; 2) if multiple categories are left choose the first (the numerically smallest).

    I’d like to solve the problem you are having. Can you tell me whether your posts fall in more than one category and whether your categories are hierarchical? It would also help if you made two bug reports — one from the settings screen of each plugin. Thanks.

  21. Hi Rob,
    Thanks for your detailed answer.
    I don’ know way, but the {categoryid} is now working fine for both plugins.

    I still have trouble to use your posted code to have the option to go further back from my posts. If I use it post from just one category and not even the most recent one get shown.
    If I use php recent_posts(); everything is fine, but unfortunately no navigation appears to go to older blog post.

    I also use your similar post plugin (you see I like your plugins a lot πŸ™‚ Is it possible that instead of “None Found” appears if there is no related post, that the hole widget disappear from the sidebar?

    Thanks a lot for your help

  22. Alfons: I’m afraid I do not understand what you are saying in your second paragraph. Sorry for being dumb. Can you explain again?

    As for the second question: the answer is not right now. If you use the plugin directly in your theme’s code there is an option to show nothing if there are no results but when you use Similar Posts as a widget the title gets output before the real plugin runs. I will see if I can change the widget code in future.

  23. Sorry for my unclear paragraph. Well, I basically use your “Recent Posts” in combination with the Exec PHP Plugin to show the latest posts on a page and not in the sidebar. Because I have a totally different layout for the index.php I use your plugin as a simple list for the most recent posts, but I don’t want to show just the first X posts. I basically want the list similar to a default index.php. So a list of post (ie. post 1-5) where I also have a navigation to go to older posts (post 6-10). Hope that’s more clear now…

  24. Alfons: If I now understand you correctly you want to use Recent Posts twice on your page: the first time showing posts 1 to 5 in one particular way and the the second showing 6 to 10 in another style. You should be able to do that — you just have to set the options for one list via the settings screens and change the settings for the second list by passing a parameter string.

    So use the settings screen to get the first list looking the way you want and then call the second one with parameters including ‘skip’, e.g.:

    
    <?php recent_posts(); ?>
    ...
    <?php recent_posts('skip=5&output_template=<li><link></li>'); ?>
    

    I hope I have understood you and that my response makes sense!

    Also, I have made changes to each of the Post Plugins (which I will release shortly) so that the widgets pay attention to the setting to show nothing in the event of no matching posts. Thanks for the suggestion.

  25. Hmmm. That’s unfortunately not quite that I was looking for. I try to explain it again. If you use a default theme for WordPress, the first page is always a list with your most recent posts and after X posts there is a link to X previous posts and on that page is again a link to even older post …and so on. That’s how basically WordPress works, right?

    So I want replicate the same functionality with your plugin. After X posts there should be a link to previous post … and so on, but I want to use the same page. It should be possible to go back as long as you want…ie even post 560 – 565.
    If I use your suggestion I have to create many pages manually.

    I wish I could show it to you, but the blog is not live yet…

    Thanks for your help

  26. Alfons: You might get somewhere combining the two techniques I have shown you so that both calls to recent posts know how many posts to skip based on the page’s query.

  27. Hi,
    I’m having a problem I believe was not mentioned before. The plugin works great, but the date is displayed wrong: the date for all recent posts is the same, as the date of the post (or page) that is displayed in the main area. For example, one post was published yesterday, another 2 days ago, but when I click on a post, that was published 10 days ago, both new posts have beside them a date of being published also 10 days ago.
    If i format the date output it does the same thing, but if i use date:raw, it displays the correct date for every post.

    Do you have any idea, what could be the reason and how to fix it?

    I’m running WP 2.6 and plugin 2.6.0.1. The result is the same on Windows and FreBSD box.

    Thanks!

  28. Hi Rob,
    I have been using post thumb revisited for my recent posts area and am ready to move to your recent posts plug in – which I’m currently using for the featured area. the problem is, when I add the template tag, it indents the image about 5px too far to the right.

    I have no idea why, as I am using it with an identical setup on halfthekingdom (for my featured posts) and it isn’t doing that. At any rate, is there a fix for this? I’m assuming I need to make a CSS adjustment but have no idea what that would be.

    many thanks,
    Sue

  29. Sue: The solution really depends on your theme’s CSS. First use your browser to view the pages source. That will show you any classes etc. being applied to the images. Then have a look at the corresponding CSS. If you use Firefox and Firebug that whole palaver is made considerably easier.

  30. Lise: Consider me nudge and reminded! When I wake up properly I’ll get to it!

    Thanks for the docs — maybe I should re-translate them into English for my site… πŸ˜‰

  31. Hi Rob,

    I’ve another question. The recent post plugin is working great by the way!

    But now the new month has started the 1st day of the month doesn’t show on top but on the bottom of the list. for example:

    now it is like this:

    31/8
    30/8
    29/8
    1/9

    It has to be
    1/9
    31/8
    30/8
    29/8

    for a better example please look at http://vtbl.nl

    I’ve sorted the posts first descending on date, and second descending on time.

    Hope you could help me out.

  32. Hi Rob,

    Thnx for your help. It doesn’t solve the problem but i fixed it anyway. It was sorted as {date:d-m-Y} no i’ve sorted it as {date:m-d-Y} and that works fine.

    grt
    Rool

  33. Hi
    I am a bit confused as i dont know what template file to edit. I want it shown on the main index posts and a single post. Im not that clued up on html so any help would be grateful. Im normally used to the easy plugins not these ones!

Comments are closed.