How to Display Recent Posts in WordPress
Displaying Recent posts often helps your users to visit them easily specially on the sidebar of a single post page. But in some designing processes people want to display recent posts in many different ways. In this post, we will show you various different ways you can display the recent posts in WordPress.
Displaying Recent Posts in a List Format
The list format is mostly used in sidebars of WordPress pages. You can display the recent posts by simply pasting the following code in a template file of your choosing for example sidebar.php:
<?php get_archives('postbypost', '10', 'custom', '<li>', '</li>'); ?>
You can change the number 10 to the number of posts you like to display.
If your theme support Widgets, then there is an easier option for you. You can simply head over to the widgets page and add Recent Posts widget to your sidebar. That will save you from editing the codes.
Displaying Recent Posts with Summary
Some people like to display recent posts with a title and a short description. There are multiple ways of accomplishing that.
The first way is:
<ul>
<?php query_posts('showposts=5'); ?><?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li><li><?php the_excerpt(__('(more…)')); ?></li>
<?php endwhile;?>
</ul>
And you make sure that the excerpt is a short description of the post. You must rewrite the excerpt to make it fit the word limit.
Another way is using the Word Limit which will save you the time of writing an excerpt because the Word Limit Plugin will automatically crop everything after the desired number of characters. For that you need to download a plugin called Limit-Post which you need to download and activate.
Once the plugin is activated paste the following code where you want it displayed in your theme files:
<ul>
<?php query_posts('showposts=5'); ?><?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li><li><?php the_content_limit(250); ?></li>
<?php endwhile;?>
</ul>
You may change the 250 to set the character limit of your desire.
Displaying Recent Posts with Full Content
Some people like to display recent posts with full content if WordPress is being used as a Content Management System (CMS).
<ul>
<?php query_posts('showposts=5'); ?><?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li><li><?php the_content(__('(more…)')); ?></li>
<?php endwhile;?>
</ul>
You may change the number 5 to whatever you like. This is mostly used to make a page look like your blog page. So you should not need this if you are not running a CMS.
Now you should be able to display Recent Posts in your WordPress blog or a CMS.
Comments
12 Responses to “How to Display Recent Posts in WordPress”Share Your Opinions
Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!
Please make sure that you have read our Comment Policy.










Good info!
I’m trying to display the latest 5 posts using the last method you described, but I can’t figure out how to get page numbers. For example, the faux blog page displays the last five posts, but there is no way to go back in time from there.
I have not been able to find a solution for this. Any suggestions?
Thanks!
Use the Super WordPress loop tutorial instead. You would just need to add the pagination code in there.
I am so glad I found this, I have been trying to do this for days and I couldnt find exactly how to do this on the wordpress codex !!! the only sollution they seemed to offer screwed up the custom homepage I built, but this works perfect.
Thanks very much.
Glad we were able to help
I want to know how to display rcenet posts with thimthumb thumbnial.
Unfortunately Google is being Google as usual and not giving me the results I want.
Thanks.
You can simply add timthumb codes anywhere in these codes, and it should work. The query will be run the exact same way. If you are looking for a step by step guide, we haven’t written one. Although we might write one in the future.
How about on spesific page – example i make new page called blog, i have try the code but get error,
There were few articles around explaining the same thing. But you elaborated the topic with additional information which is very useful. Thanks for your efforts.
i want to display posts in order of post date.. recent one first with pagination i am able to do the pagination but the posts are displaying on each page in random order somebody please help………….:(
Don’t see why it wouldn’t display posts in the order of date. The loop method would only display the most recent ones at the top.
Hi Guys
I seem to be having some issues with this code. It works great on my index.php page but when I try adding it to either the page.php or single.php it prevents other content showing. For example when I click the ‘about us’ page it will display the latest article!
Hope this makes sense and any help anyone can offer would be greatly appreciated.
Thanks
Try reading this article: http://www.wpbeginner.com/wp-tutorials/how-to-create-a-separate-page-for-blog-posts-in-wordpress/