Fall Sale! Save up to 50% now.

Recent posts in your WordPress sidebar

By team on May 31, 2008

While developing for WordPress you sometimes need to create a “non-widgetized” custom sidebar. You would also like to have a list of your most recent posts in that custom sidebar. Unfortunately, WordPress doesn’t have a “recent posts” template tag.

Here is a simple, easy to implement PHP file you can use to generate a list of recent posts in your custom “non-widgetized” sidebar.

Download this file: recent_posts.php. Now, upload it to the wp-content/themes/yourtheme directory, and insert the following code in your sidebar.php file where you want your recent posts list to appear:

<?php include (TEMPLATEPATH . "/recent_posts.php"); ?>

If you open up recent_posts.php in your favorite text editor you have the ability to change how many posts you want to display. You can also be more specific in what posts you want to display by passing different arguments to query_posts.

Enjoy this post? Read more like it in Tutorials.

“My website is absolutely gorgeous, and the support service is literally unlike any other I’ve experienced, probably in my whole life, in any industry!”

Jacqueline Smith

“I’m blown away by the generous and effective support provided. Super accessible, laid back, and knowledgeable!”

Micah Davisyes
Discover our WordPress Page Builder Now

(Over 600 small businesses got started last week)