Easily display recent posts in Wordpress
Want a quick and easy way to display a list of your most recent posts in Wordpress? Just add the following code wherever you want the list to appear in your sidebar.
<ul>
<?php
$myposts = query_posts('showposts=10&offset=0');
foreach($myposts as $post) :?>
<li>
<a href="<?php the_permalink(); ?>">
<?php echo substr(the_title("","", FALSE), 0, 24) . "..."; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
*excuse the poor indentation/structure, having a little hiccup with the syntax highlighter
This will show an unordered list containing the 10 most recent posts. If you want to exclude the most recent post, change the ‘offset’ from 0 to 1. To alter the number of posts displayed, change the number corresponding to ’showposts’. Each post title is truncated to display the first 24 characters. To modify the display length, change the ‘24′ in the substring method to your liking. To display the entire post titles, just get rid of the substr function call which is wrapping the call to the_title().
To learn more about the other parameters available for ‘query_posts’ to fine tune the output even more, visit the Wordpress codex.


