You don’t need any custom queries or database calls just to get a list of recent posts. In fact, there’s a function built into WordPress that will do just that. It’s called, wp_get_archives(). You might recognize that as a way to display monthly archives, but with a few parameters, you can modify it to display a list of recently published WordPress posts. Here’s the code:

<?php wp_get_archives('title_li=&type=postbypost&limit=10'); ?>

What this will do is strip any WordPress added formatting and output a nice list of the 10 latest posts, each within it’s own <li> tag.

Subscribe to RSS

By: Leland on May. 26

Bookmark and Share

13 Comments »

Comment by Anto Subscribed to comments via email
2008-05-27 03:22:54

You should do the same for recent comments :P

 
Comment by BANAGO
2008-05-27 10:39:00

I don’t think this can be done for comments.

 
Comment by Leland
2008-05-27 13:12:22

There is a way actually, not as easy as this though. I’ll make a post soon about doing recent comments.

 
Comment by Anto Subscribed to comments via email
2008-05-27 13:25:36

Told ya BANAGO, there is :P

I know its not as easy, but it would help people. I remember how to do it now.

 
Comment by BANAGO
2008-05-28 07:39:40

@Anto: I am sure there is as I have implemented that at almost all the blogs I have designed, but what I meant was that it is not done on the way the archive is done. :)

 
Comment by Anto Subscribed to comments via email
2008-05-28 07:47:52

Yea i know that :) I didnt say it was lol :P

Anywhoo. Nuff said

 
Comment by KimCool
2008-05-30 07:50:31

good ways~!

 
Comment by sandi
2008-08-31 09:30:27

I hope it can works in my blog

 
Comment by Tony Oravet
2008-11-26 18:37:23

This is perfect! Exactly what I needed to show the most recent posts in a church website’s main page design. Thanks so much for the tip!

 
Comment by curtismchale
2009-02-21 00:41:57

How about a version where you exclude certain categories from the recent posts? this function doesn’t allow the exclusion of categories. I am using it inside the loop before the call for the actual post title in a lefthand sidebar and found that the other version of a custom database query fed the last post title into the main post the_title(). If I use the version you supplied then it doesn’t feed the wrong title to the post but I can’t exclude a few custom categories that feed my news and portfolio.

 
Comment by awesomeguy
2009-02-26 19:46:36

Thanks a bunch, worked beautifully!

 
Comment by toure Subscribed to comments via email
2009-03-15 23:59:09

eh thanks.
what should I do to add a header to the lists?
thanks again.

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post

Recent Comments

  • Anto: Hello. Thanks, you’ve got my contact details. Get in touch with me if your wanting something in your own...
  • Sonny: Hey Anto, I love this design, good work that I paid for link removal :) Anyways, how can one contact you to do...
  • Leland: @axelk: As in picture uploads? Not sure about that, although you could set up the form to allow users to send...
  • axelk: thank you for the reply. can Contact 7 be used to submit pictures as well?
  • Leland: @axelk: I think that’s what the Contact Form 7 is for. Although if you wanted to allow users to submit...

About The Author

Welcome to Theme Lab. My name is Leland, and I run the place. I write all the tutorials and code all the themes you see here on the site.

For more information about me, feel free to read the about page. If you want to drop me a message, feel free to contact me.

Interested in advertising on Theme Lab? We have advertising available at very reasonable rates. Head on over to the advertising page for further details.

Please read our Privacy Policy and Terms of Service in regards to theme usage.

© 2009 - Theme Lab - Powered by WordPress