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!

Tags: , ,

Monday, September 15th, 2008 WordPress

6 Responses to “List recent posts in WordPress”

  1. Excellent i been looking for this, thank you

  2. albert on October 5, 2008.
  3. Thank you so much!!!

  4. Aman on November 19, 2008.
  5. Thanks for the comments :)

  6. Matt on November 20, 2008.
  7. Wasn’t actually looking for a post on this but it’s really going to help with my WordPress plug-ins.

    Cheers Matt.

  8. Stephen McIntyre on January 4, 2010.
  9. Thanks!! Exactly what I needed.

  10. david on June 1, 2010.
  11. 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.

  12. ecommerce plugin on June 8, 2010.

Leave a Reply

About Me

Matt Varone - Matias Varone - sksmatt
HI there,

I'm a freelance creative web developer, UI designer and hobbyist musician.

Twitter Status

Flickr Gallery

    Blue WallClutter drawerCS4 Replacement iconsCS4 Replacement icons