List recent posts in WordPress
— Quick tip on how to list recent posts in WordPress. This is very easy and only requires to know WP_Query and write a few lines of code.
WordPress Template File
Insert the following code in the WordPress template file you want to display the list of recent posts.
<h4>Recent Posts</h4>
<ul>
<?php
// replace 5 with the number of posts you want to show.
$aRecentPosts = new WP_Query("showposts=5");
while($aRecentPosts->have_posts()) : $aRecentPosts->the_post();?>
<li><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?> " rel="bookmark"><?php the_title();?></a></li>
<?php endwhile; ?>
</ul>
And thats it! You can see a working sample of this at the bottom of this site. Cheers!




Excellent i been looking for this, thank you
Thank you so much!!!
Thanks for the comments :)
Wasn’t actually looking for a post on this but it’s really going to help with my WordPress plug-ins.
Cheers Matt.
Thanks!! Exactly what I needed.
You got a truly helpful blog I’ve been right here reading for about an hour. I’m a newbie and your accomplishment is quite a lot an inspiration for me.