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

4 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.

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

    Clutter drawerCS4 Replacement iconsCS4 Replacement iconsMagic

Scrnshots Gallery

  • Screenshot from ScrnShots.com
  • Screenshot from ScrnShots.com
  • new site im working on
  • Screenshot from ScrnShots.com