WordPress Managed Hosting - 40% Off For 4 Months - Coupon Code: BFCM2021 Avail Now

How to Display Recent Posts Widget in WordPress

Owais Alam — July 18, 2019 6 Minutes Read
display WordPress recent post widget

Showcasing your recently published content is one of the most simple ways of improving almost every website performance metrics.

The good thing to know is that you can display your recently published content in high-traffic areas such as sidebars, after the posts and the footer. This makes sure that you give maximum visibility to your content and get all the benefits of publishing content. In this article, I will show you how you can create a recent post plugin that simplifies the process of showcasing the recent posts on your website.

Register the Plugin

I will start by registering the plugin on the website. Once registered, the plugin will show up in the Plugins section of the website.

In the code snippet above, RecentPostsWithExprects() function registers the plugin. As a result, this is how the plugin entry would appear in the Plugin list:

WordPress list posts by category

The Code of the Widget

Here is the code snippet that carries out multiple actions. First, it creates the widget that would appear on the frontend. Next, the snippet retrieves the latest published blogs. Once this is done, the excerpts (both the built-in ones and the Advanced Excerpts) of the blogs are displayed through a loop (see the comment within the snippet). Once this is done, the function wp_reset_query() restores the $wp_query and the global post data of the original main query.

The Form for the Widget Placement

The next snippet generates the form that the user will see when placing the widget on the front end. This snippet creates a simple form that the user can fill out to place the widget on the website.

Here’s how the widget’s form would look like in action:

WordPress recent posts widget

How to Set up and Use the Recent Post plugin

First, create folder having name “recent-post-widget-extended”. In this folder create file having name “recent-post-widget-extended.php”. Activate plugin than it shows in widget area as shown in fig.

WordPress recent posts widget activate plugin

To set up and get the plugin operational, create a folder named recent-post-widget-extended in the WordPress Plugin folder. In this folder, create a file and name it recent-post-widget-extended.php. Paste the code of the plugin in this file and save it.

Next, activate the plugin and you would be able to see it on the Plugin section of the WordPress Dashboard.

When you are ready, you can insert the widget in any location on the frontend of your WordPress websites

Once deployed, here is how the widget would look on the frontend:

recent posts widget extended

The Full Code of the Plugin

Conclusion

This plugin is a great way of showcasing your recently published content on the website frontend. When placed on the location of your choice, the recent posts would attract readers into further exploring your website. All you need to do is to fil out a simple form that includes the title of the post, the number of posts to be visible in the widget and the excerpt from the post.

If you need help with this plugin, Do leave a comment and I will get back to you.

Create Faster WordPress Websites!

Free eBook on WordPress Performance right in your inbox.


    Create Faster WordPress Websites!

    Free eBook on WordPress Performance right in your inbox.

      Owais works as a WordPress Community Manager at Cloudways and contributes occasionally at WPblog. He spends his time developing different websites on WordPress and finds special interest in WooCommerce.

      THERE'S MORE TO READ

      Newsletter

        WordPress Help Zone - Ultimate WordPress Pit-Stop

        Learning WordPress? Or are you expert enough to help others? Join our WP Facebook group!