How to Display Recent Posts in WordPress

This tutorial guides you how to display recent posts in WordPress. Display recent posts will help your users to get the updates from your blog easily. You can display recent posts in your website or blog sidebar, after single post,and also in your home page where you want. Basically recent post means the latest post depending on their creation time. Also many website or blog shows depending on their last modified time. In WordPress you can display recent posts with various ways.

I will show you in this article how to display recent posts in WordPress with recent posts plugin, recent post widget, WordPress recent posts shortcode, and with the recent posts function manual recent posts code. In the above mentioned different ways you can show recent posts in WordPress page and sidebar.

Learn How To Display Recent Posts In WordPress

Display Using WordPress Recent Posts Widget

Display WordPress recent posts using widget is the default or built-in feature of this CMS. This is very basic but it is effective for those users who don’t have any such technical or development knowledge in WordPress. You can add recent post widget in your sidebar or in any widget ready area in your theme. Firstly you need to do login in your WordPress admin dashboard then click on Appearance >> Widgets.

WordPress recent post widget menu

From all the listed default widget you will get the recent post widget. Simply drag and drop in the widget area where you want to display few recent posts. Below image will give you a better understanding i think.

WordPress recent post widget

Here we give an example of drag default recent posts widget and drop to the Home Sidebar widget area because i want to display the recent article in my home page sidebar. Here you can set the title, number of posts to show, post date. After filling the detail just save the widget form and you have done to display latest post in your sidebar.

In this way using WordPress default recent posts widget you can show latest article in different areas of your theme. In my case this thing output the below result in my sidebar.

WordPress recent post using widget

Displaying WordPress Recent Posts Using Shortcode

Our previous method to displaying recent or latest post is very easy but what if you need to display recent posts in WordPress page or inside the post? Then the effective and easiest way use shortcode to display. Firstly we need to install and activate Display Post Shortcode Plugin.

The Display Posts Shortcode plugin was written to allow users to easily display listing of posts without knowing PHP programming or editing template files.

display post shortcode plugin

You need to add the shortcode in a post or page, and use the arguments. You can also customize the output with parameters like: include_date, include_excerpt, and image_size. Just use the shortcode [display-posts] with your own require parameters inside the post. This plugin offers a variety range of parameters which you can use with this shortcode. Here are few examples for your understanding.

Display two Recent Post with Thumbnail

[display-posts posts_per_page="2" image_size="thumbnail"]

Display Recent Pages
In this case you just need to pass a parameter post_type=’page’.

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

Display Latest Post with Title Ordering
You can display or show latest WordPress post orderby title of these post. For that you need to use parameter orderby=’title’.

For full list of available parameters visit documentation. Also you can use this shortcode in any text widget of your theme but before that make sure enable shortcode in your text widget. To enable just add the below line in your function.php file.


Using Recent Post Plugin For WordPress

Another way to display recent WordPress post is using recent posts plugin for WordPress. As you saw that default WordPress widget serve very basics feature. But when we need some customization to show post thumbnail or something like that then we need to extend the default features of your WordPress widget which are actually provide by this plugin. With this extend plugin you can customize thumbnails, excerpt, excerpt length, read more link of your recent posts.

recent post widget extended plugin

Also with this extend plugin you can set custom css for recent posts. Below image will describe you what are the fields or area you can customize with this plugin.

 recent post widget extended plugin

Manually Display With Recent Posts Function in Theme File

The way which i always recommend to those users who have a sound knowledge of WordPress Query functions and PHP programming. In this way you can directly add recent posts code in your theme file and can display any where you want. Below code will show you how to write recent posts code in WordPress and describe the meaning of each lines of code.

// The Query with passing parameters to display recent three posts 
$the_query = new WP_Query( 'posts_per_page=3' );
// The Loop to fetch each post one by one. And run three times for three recent posts
if ( $the_query->have_posts() ) {
	echo '<ul>';
	while ( $the_query->have_posts() ) {
		echo '<li>' . get_the_title() . '</li>';
	echo '</ul>';
	/* Restore original Post Data */
} else {
	// no posts found

Here in this example we are used a standard loop. We used the default built-in class WP_Query and passed argument to that. After that if post found then run a loop and get the particular post data one by one if not found then you can display some message like no post found. In this way you can easily get the recent posts in WordPress manually with few lines of code. For more details and different parameters for that class go through once WordPress Codex.

Hope this tutorial will help you to display recent posts in WordPress. If you have any further queries regarding how to display recent posts in WordPress feel free to contact us. We will be happy to help you. Share and like will be appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *