Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Display Recent Posts in WordPress

Last updated on by
Follow WPBeginner on YouTube
How to Display Recent Posts in WordPress

Do you want to show your recent posts in WordPress? Displaying recent posts helps your users find them easily. You can add recent posts in your sidebar, after the end of your post content, inside your post content with a shortcode, in your footer widget areas, and basically anywhere else that you like. In this article, we will show you how to display recent posts in WordPress with a plugin, widget, shortcode, and the manual method with the recent post function.

A WordPress page with recent posts listed

Video Tutorial

If you don’t like the video or need more instructions, then continue reading.

Using The WordPress Recent Posts Widget

WordPress comes with a built-in default widget to display recent posts in your site’s sidebar or any widget ready area. Inside your WordPress admin, simply visit Appearance » Widgets and add Recent Posts widget to a sidebar.

Using the default WordPress recent posts widget

The built-in recent posts widget is very basic. You can provide an alternate title to the widget, show date, and add the number of posts you want to display. Next, click on the save button to store your widget settings.

Using Recent Posts Widget Extended Plugin

As you noticed that the built-in widget we mentioned above is quite limited, and it doesn’t even allow you to show thumbnails or excerpts which is often a priority for users.

What if you wanted to display thumbnails and excerpts with your recent posts? What if you wanted to limit them to specific categories or tags?

Well, that’s when Recent Posts Widget Extended plugin comes in handy.

First thing you need to do is install and activate the WordPress Recent Posts Widget Extended plugin. Upon activation, simply visit Appearance » Widgets and add Recent Posts Extended widget to a sidebar.

Recent posts extended widget settings

Recent Posts Extended widget comes with a lot options and gives you full control on how you want to display recent posts on your WordPress site. You can show thumbnails, excerpts, limit categories and tags, ignore sticky posts, and much more. You can even use the widget to display recent posts from any other post type on your site.

Recent posts with thumbnail and excerpt in  sidebar widget

Displaying Recent Posts in WordPress Using Shortcode

Adding recent posts to a sidebar is fairly easy, but what if you wanted to show recent posts inside a WordPress post or page? The easiest way to display recent posts in WordPress posts and pages is by using shortcodes.

First thing you need to do is install and activate the Display Posts Shortcode plugin. It works out of the box and there are no settings for you to configure.

Simply edit a post or page where you want to display your recent posts. Next, use the shortcode [display-posts] with your own parameters inside the post. The plugin offers a whole range of parameters that you can use with the shortcode. Here are some examples:

Display 5 recent posts with thumbnails and excerpt

[display-posts posts_per_page="5" image_size="thumbnail" include_excerpt="true"]

Display recent pages instead of posts

[display-posts posts_per_page="5" post_type="page"]

Change the order to title instead of date.

[display-posts posts_per_page="5" orderby="title"]

Display recent pages under a specific parent page.

[display-posts posts_per_page="5" post_type="page" post_parent="5"]

For a full list of parameters visit the plugin’s documentation.

You can also use these shortcodes inside a text widget, but first you will need to enable shortcodes in your text widgets by adding this code to your theme’s functions.php file or a site specific plugin.

add_filter('widget_text', 'do_shortcode');

Displaying Recent Posts Manually in WordPress Theme Files

More advanced WordPress users may want to add recent posts directly in their WordPress theme files. There are multiple ways to do this, but the easiest one is to use the built-in WP_Query class. Simply add this code where you want to display the recent posts.

<ul>
// Define our WP Query Parameters
<?php $the_query = new WP_Query( 'posts_per_page=5' ); ?>

// Start our WP Query
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

// Display the Post Title with Hyperlink
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>

// Display the Post Excerpt
<li><?php the_excerpt(__('(more…)')); ?></li>

// Repeat the process and reset once it hits the limit
<?php 
endwhile;
wp_reset_postdata();
?>
</ul>

This code simply displays five most recent posts with their title and excerpt. The WP_Query class has tons of parameters that allows you to customize it any way that you like. For more information please refer to the codex.

We hope that this article helped you learn how to display recent posts in WordPress. If you want to customize the display of your recent posts without writing any code, then you may want to check out CSS Hero, a WordPress plugin that helps make design customization easy – see our full CSS Hero review.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.


Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. Jason says:

    The version I downloaded does not include the ability to display thumbnails…cant see the option anywhere. I am using version 0.9.9

    Any clues?

  2. andrea says:

    Hi, my issue is to display the latest post full content in a static home page… and i was thinking that the last snippet was what i needed… but unfortunately it does not works properly. In effects it shows title but not the content. could u help me please

  3. Tushar says:

    Hi I am new on wordpress, I want to show Client Testimonial using post….How should I do it..? any suggestions please ?

  4. WPBeginner Staff says:

    Here is an easier way. Install Display Posts Shortcode plugin. Create a blank page and add the shortcode as described in plugins documentation. Publish the page. Go to Settings > Reading and select the page you just created as your static page. Redit the static page and add the slider just before the display posts shortcode. Hope this helps you.

  5. Emily says:

    Hi, I am wanting to add a slider to the top of my homepage, but it will only allow me to do so if I use a static page. Right now when you go directly to my website, it is my latest posts in full length. If I change my homepage to a static page so that I can include the slider, will this work to add the recent posts below, just as it appears now? Where would I be posting this code? Into the static homepage?

    Note– I recently tried messing with my php and broke my code and had some major issues.. so I’m pretty nervous messing with php.

  6. Subrata says:

    hi!…can anyone tell me how to display top rated blog posts (only 5) in increasing order (numeric order) by using PHP codes?

  7. Oliver says:

    Hi there. I am a designer so I’ve never been good at PHP. At least I can read and change it for my conditions most of the time. This time I’d like to call for the nine latest posts excluding the very last one inside my slideshow container.

    For now I just set the first post on display none. This works fine; however the slideshow still counts to ten. That’s why you find the last page empty.
    Is there any way to exclude the very last post when calling for recent posts? Thank you so much in advance!

  8. KalanaDe says:

    Hi, I want to display blog posts only from a category called ‘Blog’ only. (I want to exclude all other posts from other categories.) What should I add to this code.?

  9. Bucur says:

    showposts is deprecated. However, posts_per_page is perfect for use with query_posts(), or even more particularly, WP_Query::query().

    numberposts may be the equivalent argument for get_posts().

  10. Dan says:

    This worked perfect! Thanks a lot to the author of this article.

  11. Gabriel says:

    The link to Limit-Post Plugin doesnt work!?

    • WPBeginner Support says:

      Thanks for notifying us. We have updated the article with a new code snippet that does not require you to install any plugins. Hope this helps.

  12. Art says:

    Good article.

    One piece of info that would increase it’s usefulness though, is how to (or a plugin that can) include an offset.

    For example, I want my two most recent posts to be full text — got that.
    But what if I want the next 10 to be excerpts, and maybe the next 10 older to be headlines only — the list?

    So — how can you include an offset?

    Cheers,
    Art

  13. Ryan says:

    Hi there,

    I want my latest 4 posts to display inline across the screen, how would I do this?

    Currently they only display down the page.

    Thanks

    Ryan

    • Mike says:

      Sounds like you need to create a container with the height/width you want the posts to appear as. Then allow them to wrap over.. make sure that the last piece of your “Post” code doesn’t have a line break.

  14. Wilko says:

    Great post! Thanks!

    Just one question. Is it possible to hide the latest post out of 5? I mean on my website I display the latest post already with full content, so I would like to hide the first.

    • WPBeginner Support says:

      Change your WP_Query like this:

      <?php $the_query = new WP_Query( 'showposts=5&offset=1' ); ?>
      
  15. Captain Code says:

    Exactly what I was looking for!

    Thank You =)

  16. Actors Alliance says:

    Where do I input the code to change the number of full posts displayed?

  17. Amanda says:

    Lovely! Is there a way to make the headers of each post H2 ? And, can I hide a category?

    • Editorial Staff says:

      Yes use the second method and wrap it around h2. Use wp_query codex page to look at the parameter for hiding categories.

  18. Jeremy says:

    Finally a quick and to the point tutorial on this topic. Other posts on calling in the recent blog posts were not as quick and too the point. Thanks :D

  19. Ellery Davies says:

    Hi Syed,

    I use the WordPress Twenty-Eleven theme and have always displayed recent posts using the widget in Jetpack. But I want this list to show in the individual posts as well. Is there a way to do this? If it involves pasting code, into which file do I paste?

    • Editorial Staff says:

      Where in the individual posts do you want to show that list? Below post? Sidebar?

      • Ellery Davies says:

        The home page of AWildDuck -d0t- com, shows recent posts along the right side, along with subscribe and a tag cloud. But this appears only on the home page. If I send you a link to any individual post (or if you click on the title of any post), the right frame disappears. My visitors can no longer see a list of recent posts. I am very frustrated by this, and I want to know how to get that list of recent posts to appear on all pages. (Not just the home page).

        • Editorial Staff says:

          Go to Appearance > Theme Options. Change the default Layout to content on left.

        • Ellery Davies says:

          Hi Syed,
          Indeed, this is my current setting. It has always been my setting. Twenty Eleven with “Content on left”.

        • Editorial Staff says:

          Hmm that’s weird because that’s what I have and it is working fine.

        • Ellery Davies says:

          I don’t understand… Do you see Recent Posts on the right, even when you are looking at an individual post? If you do, are you using JetPack/Recent Posts?

          If the answer to both questions is “Yes”, would you please send me your phone number. You already have my email address. -Or call me: Area code “Five-Oh-EIght”, 485 ..695O.

          Thanks, –Ellery

  20. darknote says:

    Thank you and with the_post_thumbnail ?

    • Editorial Staff says:

      Simply add the_post_thumbnail(); and style it however you like.

      • darknote says:

        thank you, yes, but I ask not only for me but thinking of other visitors, it can be more useful in your article, give an example of recent articles with thumbnails.

      • Kylie says:

        Thanks so much for this tutorial! I used the code to display recent posts with a summary on my website’s homepage.

        When adding the_post_thumbnail(); code could you please tell me what file and where in the file to add it? I tried looking it up and experimented by adding it to several files on my own and was not able to get the thumbnails to show up.

        Any insight would be greatly appreciated.

        Thank you,

        Kylie

        • WPBeginner Support says:

          In your Post Edit area, post thumbnails are called featured image. If you can not see a featured image meta box, then click on Screen Options button on the top right corner of your post edit screen and check Featured image.

  21. vajrasar says:

    Nice Post.
    How can I achieve – Recent Posts in Menu. Like I have my category “Crime” on top-menu. Now whenever a user hover it, I want to show 5 recent posts from category “Crime” with their thumbnails?

  22. muhabas says:

    Spent a lot of time to find out this information which works for me 100%. Its very easy and to the point. Thanks…… God bless you.

  23. wanted20 says:

    Hello. I have a website with 3 subdomains. It’s possible to display in a widget in the main domain the lastest posts from a subdomain?

  24. cwdcreative says:

    The link to the “limit-post” plugin does not work. Do you have a current link or an alternate?

    Thank you!

  25. broghanreilly says:

    I have tried to use this code and it doesn’t seem to work? I am a beginner and am using a standard theme and not hosting. Therefore I can’t upload anything I can only use HTML.

  26. doodark says:

    Thanks so much for posting such a useful and concise article. Much appreciated!

  27. YiLiu says:

    very usefull for me.thanks

  28. Tiago Araujo says:

    Thank you very much for the post, I was looking for it for a while and found your explanation pretty simple and useful. Code worked just fine for me!

  29. Panoz says:

    My WP homepage has a footer displaying the titles of my 4 latest posts (Recent Posts). This makes no sense, as these posts are already displayed above.

    My question is how can my footer display the range between 5th and 8th post ??

    The code its currently using is

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

    Many thanx in advance for your help

    • Editorial Staff says:

      You can’t use wp_get_archives for that. You would have to run a loop and add the query_post function with the offset parameter.

      • Panoz says:

        Thank you very much for your kind reply. Can you please let me know how I can do that? I know very few stuff and i definately need to have this done by the day after tomorrow that I’m launching my site.
        Thanks

  30. Phelan says:

    I’ve been looking for this code for a few days now. I can’t believe it’s not more readily available in the Template Tags pages or any other blogs.

    I changed the code to include tags and tags instead of the tags like the following:

    <a href="”>

    Thanks for posting!

  31. Katie says:

    One problem with the above code is when you call that function in your sidebar which is called before the start of the loop in single.php. Your single.php file will list down all the articles of your blog post irrespective of the one which is called.

    In such cases, you can also use

    Otherwise, calling query_posts(‘showposts=10’); function is fine.

    Both of them will list down latest 10 posts in ul, li format. This is bit easier.

  32. Mike says:

    Hi, is it possible to show the date before the linked post title when using:
    <?php get_archives('postbypost', '10', 'custom', '’, ”); ?>

    Thanks

  33. ali says:

    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

  34. ravi says:

    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………….:(

    • Editorial Staff says:

      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.

  35. Abhijit V. Chaore says:

    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.

  36. seminyak bali says:

    How about on spesific page – example i make new page called blog, i have try the code but get error,

  37. Mark says:

    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.

    • Editorial Staff says:

      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.

  38. DaveK says:

    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.

  39. Justin says:

    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!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.