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

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 wp_get_archives( array( 'type' => 'postbypost', 'limit' => 10, 'format' => 'html' ) ); ?>

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 $the_query = new WP_Query( 'showposts=5' ); ?>

<?php while ($the_query -> have_posts()) : $the_query -> 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 to limit the number of characters displayed in the content is by manually stripping out post content during the query to display only a limited number of characters. To do that use this code:

  <ul>
    <?php $the_query = new WP_Query( 'showposts=5' ); ?>

    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>

    <li><?php echo substr(strip_tags($post->post_content), 0, 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 $the_query = new WP_Query( 'showposts=5' ); ?>

<?php while ($the_query -> have_posts()) : $the_query -> 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.


Editorial Staff at WPBeginner is a team of WordPress lovers 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 »
  • Oliver

    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!

  • KalanaDe

    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.?

  • Bucur

    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().

  • Dan

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

  • Gabriel

    The link to Limit-Post Plugin doesnt work!?

    • http://www.wpbeginner.com/ WPBeginner Support

      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.

  • Art

    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

  • Ryan

    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

      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.

  • Wilko

    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.

    • http://www.wpbeginner.com/ WPBeginner Support

      Change your WP_Query like this:

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

    Exactly what I was looking for!

    Thank You =)

  • Actors Alliance

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

  • Amanda

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

    • http://www.wpbeginner.com Editorial Staff

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

  • Jeremy

    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

  • Ellery Davies

    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?

    • http://www.wpbeginner.com Editorial Staff

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

      • Ellery Davies

        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).

        • http://www.wpbeginner.com Editorial Staff

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

        • Ellery Davies

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

        • http://www.wpbeginner.com Editorial Staff

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

        • Ellery Davies

          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

  • darknote

    Thank you and with the_post_thumbnail ?

    • http://www.wpbeginner.com Editorial Staff

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

      • darknote

        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

        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

        • http://www.wpbeginner.com/ WPBeginner Support

          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.

  • vajrasar

    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?

  • http://www.muhabas.co.uk/ muhabas

    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.

  • http://www.neintrebi.ro/ wanted20

    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?

  • http://www.CWDCreative.com/ cwdcreative

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

    Thank you!

  • broghanreilly

    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.

  • doodark

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

  • YiLiu

    very usefull for me.thanks

  • http://www.tiagoaraujo.com Tiago Araujo

    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!

  • http://www.bmwforum.gr Panoz

    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

    • http://www.wpbeginner.com Editorial Staff

      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.

      • http://www.bmwforum.gr Panoz

        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

  • http://phelanriessen.com Phelan

    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!

  • http://www.stylishandtrendy.com Katie

    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.

  • Mike

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

    Thanks

    • http://www.wpbeginner.com Editorial Staff

      To do that, the better option would be to run a new loop.

  • ali

    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

  • http://www.carplanet.com.au ravi

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

    • http://www.wpbeginner.com Editorial Staff

      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.

  • http://www.abhijit.biz Abhijit V. Chaore

    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.

  • http://www.seminyak-hotels.net seminyak bali

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

  • Mark

    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.

    • http://www.wpbeginner.com Editorial Staff

      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.

  • http://www.davidkendallwebdesign.co.uk DaveK

    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.

    • http://www.wpbeginner.com Editorial Staff

      Glad we were able to help :)

  • http://www.broadbandexpanded.com Justin

    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!

    • http://www.wpbeginner.com Editorial Staff

      Use the Super WordPress loop tutorial instead. You would just need to add the pagination code in there.