Display Recent Posts without Plugin
On many WordPress themes you see a section (often in the sidebar) where recents posts are displayed. This is useful both for users and search engines. Users get an overview about the newest articles and find them easy without scrolling the whole blog page. Spiders of search engines get a delicious list with all the permalinks of the latest articles and you make it easier for them to spider your website.
There are plenty of plugins and widgets helping you to display a special number of the latest posts of your blog. But if you’re looking for a simple method to display a list with x recent posts, you don’t need a plugin (we should try to use as few plugins as possible) or a widget. Put it right into your WordPress theme wherever you want… in the sidebar, below the loop in the single post view, in the footer etc.:
<ul>
<?php $recent = new WP_Query("showposts=5"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>In this example the output would be an unordered list of the permalinks of the latest 5 posts no matter of which category.
If you want to display only the 3 latest posts of category 6, add the following to your WordPress theme:
<ul>
<?php $recent = new WP_Query("showposts=3&cat=6"); while($recent->have_posts()) : $recent->the_post();?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>You see how simple it is?
Let’s try to make your WordPress theme more powerful and use less plugins.
Get more useful WordPress Tips.


20. Oktober 2008
Thanks for that quick tip. I really think that I use too many plugins and that I want to cut back on how many resources that I use.
10. November 2008
Hi, This is a very useful post, but the font used on your site makes it really hard to read. A friendly suggestion would be to make the text color easier to read
16. Dezember 2008
Is there a way to exclude the most recent post?
16. Dezember 2008
@John:
In this case you could use the offset parameter like this:
$recent = new WP_Query(“showposts=5&offset=1″);
27. Februar 2009
Thank you very much for this useful tip !
6. März 2009
Great article. Smaller than a plugin; Saved page load time.
7. Mai 2009
Why would you want to use a new query, when you simply could do wp_get_archives(‘type=postbypost&limit=10′).
Way better.
8. Mai 2009
Thanks Pontus,
this post is a bit older. Today I would have done it your way
1. Juli 2009
Where do you exactly place the code $recent = new WP_Query(”showposts=5&offset=1″); to make it work??? Thanks
4. Juli 2009
if you need offset function you can use this code
have_posts()) : $recent->the_post();?>