How to Display Recent Posts in WordPress
Many times we need to display recent posts on the side bar or content page of WordPress blogs. If it is for the sidebar, we can use existing widget to display recent posts. But for the content, we need to use a shortcode. You can use this code on any play where you want to display recent posts. In this article, I will show you how to show recent posts in WordPress. I will show you all the ways including plugin, widget, shortcode or manual code way to show recent posts in WordPress.
So Here I am adding different ways to display recent posts on WordPress
Display WordPress Recent Posts using a Widget
WordPress comes with a built-in default widget. You can simply visit Appearance » Widgets and add Recent Posts widget to a sidebar.
The built-in recent post widget is very basic. You can only add the title of the widget and select the number of posts you want to display.
Display WordPress Recent Posts using a Plugin
As you have seen, the built-in recent post widget is very basic. So you can use a third-party plugin that not just lets you select the number of posts but more option. There is a good plugin called Recent Posts Widget Extended. This plugin adds a Recent Posts Extended widget that you can add in sidebar or footer. The widget lets you select thumbnails or excerpts along with a number of posts you want to display.
Another good thing about the plugin is that it also supports shortcode. So, you can also display recent posts within the post or page content. Here is the sample shortcode.
If you also want to include thumbnail, here is the shortcode.
[rpwe limit="10" thumb="true"]
Displaying Recent Posts with Summary manually in a theme file
If you are created a custom theme page where you want to show recent posts, you can 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 the_excerpt(__('(more…)')); ?></li> <?php endwhile; wp_reset_postdata(); ?> </ul>
Here you can change the number 250 to any number. It represents the number of characters of summery that will be displayed along with the title of recent posts. Use CSS to beautify this list od recent posts.
You can make your own widget or shortcode using the code above for showing recent WordPress posts within the post content or in side bar.
If you think there are more easy ways to show recent posts on the page, you can share it with us. If you like this post, share it with your friends on various social media websites. You can always content me if you need any help in WordPress or website development.