Display Recent Posts From A Specific Category In WordPress

Display Recent Posts From A Specific Category In WordPress

Sometimes we want to display posts only from a specific category. This can be added to sidebar or footer to show posts from a category. There can be various reasons for this. By default, WordPress does not allow this, but there are few ways by which you can add this. Most of the modern themes now come with the recent post widgets, but very rare themes offer recent posts by a specific category. If your WordPress theme does not offer this, you can try the methods given below to add the recent posts from a specific category.

Display Recent Posts From A Specific Category In WordPress

These are the main ways to display recent posts from a specific category.

  • Category Post Widget
  • By Editing theme code

Category Post Widget:

This is the simplest way of adding posts from a specified category. Category Posts Widget is a nice WordPress plugin which allows users to add the list of posts from a category on any of the widget available. This also has some customizing options from where the user can set a number of posts to display, thumbnails and many other things. The user can add as many widgets as he wants and can also set for different categories.

Install Plugin From here

By Editing Theme code:

If you are a PHP programmer and have some understanding of PHP themes, you can also follow this manual method of adding posts by category.

Use this code and add it in the functions.php file of the WordPress themes.

while(have_posts()) : the_post();
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<ul><li><?php the_content(); ?></li>
<?php endwhile; ?>

Change the Cat=1. Here 1 is the id of the category from which we want to display the posts. Change this id to pick which category will you be displaying.

If you do not know how to get the category id to use in the code.Go to Posts -> Categories and look for the category you want to use. Below the category, you will see the link to Edit. Click on it and open the edit page of the category. Now see the URL and you will get the parameter tag_ID=value. here the value is the category id.

For the example this is the edit URL of a category on my site: https://www.usethistip.com/wp-admin/term.php?taxonomy=category&tag_ID=48&post_type=post

Here the category id is 48.

So find out the category id and use in the code.

Final Words

Now you know how to display recent posts by a category in your WordPress site. If you still face any problem or want to say something, you can comment below.If you have something to add in the story or suggest something, I will be happy to see youe comment.

Tags: | |

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Similar Articles


Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

2020 UseThisTip | Part of Techlomedia Internet Pvt Ltd Developed By Deepanker