WordPress: Show Recent Posts on Homepage or in Sidebar

by Yang Yang on February 27, 2009

in WordPress How To & Walkthrough

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>

Related Posts

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

Leave a Comment

Previous post:

Next post: