WordPress: Show Recent Posts on Homepage or in Sidebar

by Yang Yang on February 27, 2009

Share This Article:
Subscribe to Kavoir: blog feed

There used to be a plugin to grab and display most recent blog posts from WordPress database. Well, while you still can use it to get recent posts and them shown on homepage or in sidebar, you can now conveniently add a recent post widget from the WordPress control panel => Appearance => Widgets if your current theme is widget ready.

Use a Recent Posts Plugin

Lots of them!

Add Recent Posts Widget

Log in to your WordPress control panel and head to Appearance and on to Widgets, there’s this Recent Posts widget that you can instantly add to your theme. Make sure the theme you are using is enabled for widgets.

Rely on WordPress Template Tags Function

What you need is the WP template function wp_get_archives(). For instance, to show the latest 10 posts in sidebar, just insert the following line of PHP somewhere in sidebar.php:

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

Or in kavoir.com’s case, I added both the lists of 10 most recent posts as well as the 5 most recent comments in footer.php:

<ul class="recent-posts">
<?php wp_get_archives('type=postbypost&limit=10'); ?>
</ul>
<ul class="recent-comments">
<?php if (function_exists('mdv_recent_comments')) {mdv_recent_comments(5);} ?>
</ul>
Share This Article:
Subscribe to Kavoir: blog feed

You should also read:

{ 6 comments… read them below or add one }

RaiulBaztepo March 29, 2009 at 9:01 am

Hello!
Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I’v just started to learn this language ;)
See you!
Your, Raiul Baztepo

Reply

Waterman pens April 1, 2009 at 4:04 pm

Woww, Thank you brother . Very good theme .

Reply

Yang Yang February 26, 2010 at 4:50 pm

WTF?

Reply

xdoppel August 14, 2010 at 7:12 pm

Thank you for your post. It’s interesting.

Reply

kntowrry September 20, 2010 at 9:59 am

I am interested in putting the most recent posts on my Homepage. The Homepage will not be part of Wordpress though. Is this post only about putting the last posts on Wordpress homepage?
Thanks

Reply

Yang Yang September 21, 2010 at 12:10 am

I’m afraid it is.

However you can achieve this by reading your WP database by your own PHP code in your own homepage.

Reply

Leave a Comment

Previous post:

Next post: