WordPress Recent Posts Plugin

by ian.purton

This PHP code will give your WordPress blog a recent posts list as I have on my sidebar to the right.

It’s not actually a plugin, you need to cut and paste this code into the sidebar.php of your theme.

Recent Posts

  • I am trying to be clever(ish) and use your script to generate a list of ALL post titles on a single page (possibly even include the contents of the description meta-tag as a snippet.

    However pasting the php into a new WP generated page just gets rendered as text. Do you know a way around this WP?

    I can't believe WP does not have this kind of feature by default - the only thing users can do is list the entire post content for categories but I just wan the more user friendly title/description tag.

    TIA, Brian
  • Matt Blank
    Great script! But can it be altered so that it will not list the post your are currently on?

    i.e I'm viewing my third latest post, so the list on the left will show posts 1 and 2, then 4 - 11??

    Thanks!
    Matt
  • Just a note ... I added the following line to your code in order to elimate "pages" from being displayed. On the site that I was working on, I only wanted "posts" to display ...

    After the line that contains the "WHERE" clause, I added:

    $sql .= "AND $tableposts.post_type = 'post' ";

    Great function! Thanks!
  • If you want to only include posts, add the following code to the script on the line BEFORE "$sql .= "GROUP BY $tableposts.ID ORDER BY."

    Code to add: $sql .= " AND $tableposts.post_type = 'post' ";
  • Chris
    Nice, although I have the same problem as Bock the Robber-- how can I exclude pages and only include posts??
  • Thanks. This worked perfect and was exactly what I was looking for.
  • Thanks,

    It works great on my blog. How did you get it to work with comments as well?
  • Hi. This is a nice little feature. However, I notice it picks up pages as well as posts. Do you think it could be refined to show posts only?
  • This is a great help! Thanks for this mate
blog comments powered by Disqus