Family Encyclopedia >> Electronics

How to display recent posts from a specific category in WordPress

Do you want to display recent posts from a specific category in WordPress? The default recent posts widget shows posts from all categories, and there is no option to filter them by category. In this article, we will show you how to easily display recent posts from a specific category in WordPress.

How to display recent posts from a specific category in WordPress

Filter posts by category in WordPress

If you only want to create a page to display recent posts from a particular category, then your WordPress site already has separate pages for each category.

You can add links to all your category pages by visiting Appearance »Widgets and add the 'Categories' widget to your sidebar. You can also add categories in your navigation menus.

On the other hand, if you want to display recent posts from a specific category in your sidebar, then there is no default widget for that. The default recent posts widget does not allow you to filter posts by category or tags.

Fortunately there is another way. Let's take a look at how to easily display recent posts from a specific category in WordPress.

Video Walkthrough

Subscribe to WPBeginner

If you don't like the video or need more instructions, continue reading.

Method 1. Show recent posts from a category using the plugin

This method is easier and is recommended for most users.

The first thing you need to do is install and activate the Extended Recent Posts Widget plugin. For more details, check out our step-by-step guide on how to install a WordPress plugin.

Upon activation, you need to visit the Appearance »Widgets page and add the 'Extended Recent Posts' widget to your sidebar.

How to display recent posts from a specific category in WordPress

The widget's menu will expand to show its settings. You must select the category or categories you want to display in the 'Limit to category' option.

The widget comes with many options that you can customize. You can display post thumbnail, date, relative date, post summary/excerpts and more.

Don't forget to click the Save button to store your widget settings.

You can now visit your website to see recent posts displayed by category.

How to display recent posts from a specific category in WordPress

Show recent posts by category using Shortcode

The Extended Recent Posts widget also allows you to use the shortcode to display recent posts anywhere on your site, including posts and pages.

You will need to edit the post or page where you want to display recent posts from a specific category. In the post editor, you will need to add the following shortcode:

[rpwe limit = "5" extracto = "true" cat = "72"]

This shortcode displays 5 recent posts from a specific category with the post excerpt. You'll need to replace the cat value with the ID of the category you want to display. See our article on how to find the category id in WordPress.

After adding the shortcode, you can save your post or page to see your changes.

How to display recent posts from a specific category in WordPress

Method 2. Show recent posts from a specific category using a code snippet

This method requires you to add code to your WordPress theme files. If you haven't done so before, check out our guide on how to copy and paste code in WordPress.

You will need to add the following code in your WordPress theme files where you want to display recent posts from a specific category.

 
    have_posts ()): $ catquery-> the_post (); ?>

The first line of this code creates a new WordPress query with a specific category ID. You need to replace it with your own category id. It only displays the post title in a list.

You can change it to display the full content by adding the following code:

 
    have_posts ()): $ catquery-> the_post (); ?>

You can also replace the el contenido with el extracto to show post excerpts instead of full article.

We hope this article will show you how to easily display recent posts from a specific category in WordPress. You may also want to see our list of most wanted category hacks and plugins for WordPress.

If you enjoyed this article, please subscribe to our WordPress YouTube Channel video tutorials. You can also find us on Twitter and Facebook.