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
<?php
function get_recent_posts ($num_posts = 10)
{
global $wpdb, $tableposts, $post, $tablepost2cat;
if (!isset($tablepost2cat)) $tablepost2cat = $wpdb->post2cat;
if (!isset($tableposts)) $tableposts = $wpdb->posts;
$orderby = "$tableposts.post_$orderby";
$now = current_time('mysql');
$sql = "SELECT DISTINCT * FROM $tableposts ";
$sql .= "WHERE $tableposts.post_date <= '$now' AND ( $tableposts.post_status = 'publish' ";
$sql .= "OR $tableposts.post_status = 'sticky' ";
$sql .= ") ";
$sql .= "GROUP BY $tableposts.ID ORDER BY $tableposts.post_date DESC";
$sql .= " LIMIT 0, $num_posts";
$posts = array();
$posts = $wpdb->get_results($sql);
if (empty($posts)) return;
echo '<ul>';
foreach ($posts as $post) {
$title = the_title('','', false);
echo '<li>';
echo '<a href="'.get_permalink().'" title="View'.htmlspecialchars(strip_tags($title)).'">'.$title.'</a>';
echo '</li>';
}
echo '</ul>';
} //end function get_recent_posts()
get_recent_posts();
?>

Jay Unsworth
This is a great help! Thanks for this mate
Link | November 19th, 2006 at 6:01 pm
Bock the Robber
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?
Link | May 19th, 2007 at 5:15 am
MultiZ
Thanks,
It works great on my blog. How did you get it to work with comments as well?
Link | July 18th, 2007 at 5:13 pm
Jeremy Myers
Thanks. This worked perfect and was exactly what I was looking for.
Link | July 26th, 2007 at 3:53 pm
Chris
Nice, although I have the same problem as Bock the Robber– how can I exclude pages and only include posts??
Link | July 29th, 2007 at 7:41 pm
Recent Posts Plugin
[...] involved. No uploaded files or manipulating funny codes. Just copy and paste the code from this wordpress recent plugin page into your sidebar.php, and that’s it. All done. It was the simplest add-on I’ve ever [...]
Link | September 26th, 2007 at 7:55 pm
Elliott
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’ “;
Link | December 18th, 2007 at 10:54 am
Scott C. Lemon
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!
Link | February 9th, 2008 at 12:14 am
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
Link | March 27th, 2008 at 8:27 am
Brian Clifton
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
Link | March 26th, 2009 at 6:44 pm