WordPress is the best platform for blogging and content management. Most of the popular blogs in the world have WordPress in their background. There are awesome free and premium themes available for different types of blogs, and hence, as a newbie, you should always choose WordPress to create your blog. One of the most important functions of a blog is to show its visitors all the latest and recent posts. Nobody would like to come to your blog if you keep on showing the old posts category wise.
Display Recent Posts From A Specific Category In WordPress – The Problem Arises
There are two ways by which you can show you latest posts – one is by showing them in the slider or through the first section of the homepage with a label Recent Posts. The second is by having a sidebar widget where a handful of latest posts can be displayed. But the problem that some bloggers face is that when you have a blog containing multiple categories of posts, if you show a handful of recent posts then some of the latest posts of specific categories may never get the chance to show up on the list. For example, let us consider that your sidebar widget shows five recent posts and you have ten categories and you are publishing one post for each category every day. So, naturally, five posts won’t be displayed, and your visitors are probably not going to know about them at all.
Therefore, it is important to display recent posts from a specific category in WordPress. You can highlight only one category and your visitors will understand that and check out other categories manually. You can also have multiple widgets showing latest posts of each category. There are two ways by which you can display recent posts from a specific category in WordPress.
Display Recent Posts From A Specific Category In WordPress – Using Third-Party Plugin
The first step is to install the plugin named Category Posts Widget. To install it, go to your admin dashboard, and place your mouse pointer on Plugins on the left menu. You will see a drop down menu from where you have to select Add New. In the next screen, search the plugin Category Posts Widget by its name and once it appears, click on Install button and then to the Activate button.
Once the installation and activation are done, you have to come back to the admin dashboard. From there, go to Appearance option and from the drop down menu, select Widgets. In the Widget screen, under Available Widgets, find Category Post Widget. Click on it, and it will expand with a few setting options.
Give a Title, select the Category to display recent posts from a specific category and enter the number of posts you want to show. You can also set the sorting parameter which is generally Date and whether to show post excerpt and set excerpt length. You can also choose to show post thumbnail and define thumbnail dimension. Once all the settings are done, click on Save button.
Now, you have to drag the widget to the section where you want to place it. You will find the sections like Front page Content section, Right Sidebar, Left Sidebar, Header section, Top Ad Section, Footer section and likewise depending on your theme. Click on the one where you want to display and drag the Category Post Widget from the left and release in its body. Go to your homepage and check the change.
It is important to note that this method is the best and easiest method to display recent posts from a specific category in WordPress. It is recommended for the beginners but advanced users can follow the following method, and you do not have to add a third-party plugin at all. Furthermore, you will have a few extra customization features.
Display Recent Posts From A Specific Category In WordPress – Using Coding
This is an advanced method where there is no need to install a third-party plugin, and you would require a code snippet only to display your desired category’s recent posts. Again, there are two different ways to do it – one by creating a site-specific WordPress plugin and the second is by pasting the code snippet in functions.php file.
By Creating Site Specific Plugin –
You have to access your website’s folder structure through FTP. Go to wp-content folder and then to Plugins. Under Plugins, create a new folder and give a meaningful name say Plugin 1. Under Plugin 1, create a file and name it anything you want but make sure it has .php as its extension. Now, open the file and type the following code snippet. After that replace ‘announcements’ with the category name whose recent posts you want to show.
For those who are curious what this code does, it simply asks WordPress to fetch ten recent posts of the category you mentioned and display it with its thumbnails in bulleted points.
Go to admin dashboard and then to Plugins from the left menu. Click on Installed plugins. Find the plugin that has the name same as the filename you created and activate it. Then go to Appearance from the admin dashboard and click on Widgets. There you will see the installed and activated plugin that you created and place(by dragging) that to the widgets where you want to show them like front page, sidebar or in available widget space.
By Pasting in Functions.php
Go to Appearance and then to Editor. Find the file functions.php and edit it. Add the following code snippet in it, replace ‘announcements’ with your category name and save it.
Go to Appearance and then to Widgets. Click on the widget area where you want to display the recent posts from a specific category. Create a text widget inside it and write [categoryposts]. If you check the code snippet, you would understand that [categoryposts] is a shortcode to call the function.
Similarly, if you want to paste the widget anywhere in a post, just write the shortcode and publish the post to see the recent posts.