Last updated on

The WordPress Core Recent Posts Widget is an easy way to display the most recent posts to your visitors. Unfortunately there isn’t a way to only show recent posts from a specific category (or categories) without the use of a plugin.

To find a solution, we did some testing using the Recent Posts Widget Extended and Widget Logic plugins. While they do not work with themes using the new block widget interface like Twenty Twenty-One, they do work well together in other WordPress themes.

If you are using Twenty Twenty-One, you should consider using the Display Posts plugin to accomplish the same goal. Since this plugin uses shortcodes instead of a visual interface, it will work with Twenty Twenty-One.

Each plugin will be discussed in greater detail below and an example of how they can work together to give you greater control over what posts your users see in widgets.

Please note that these plugins have a warning that it hasn’t been tested with the most recent versions of WordPress. We strongly advise you test this plugin in a WordPress staging environment with your theme and current plugins to ensure compatibility.

Create a Recent Posts by Category Widget

Approach 1: Use Recent Post Widget Extended Plugin

The Recent Posts Widget Extended plugin allows you to create a recent post list with posts only from a single category. You can also use the plugin to create other types of post lists (recent or not) using the available settings. It adds a new widget to your dashboard.

  1. Navigate to Appearance > Widgets.
  2. Select Recent Posts Extended from the widget list.
    Recent Post Extended Widget
  3. Add the widget to the desired widget location, which will vary by theme.
  4. You can leave most settings as they are, but be sure to look at these:
    • Title
    • Number of posts to show
    • Display Thumbnail
    • Display Readmore
  5. In the Limit to Category box, check the category or categories you’d like to display posts from.
    Recent Posts Extended plugin options
  6. Navigate to the front end of your website to see your new widget!
    Post List in WordPress

As shown above, there are many options you can use to customize each Recent Post list. Feel free to experiment with different options to create unique post lists.

Approach 2: Use Display Posts Plugin

You can also use the Display Posts plugin to create a post list by category. You will use a shortcode to choose what displays – excerpt, image, read more link, etc – using the instructions on the Display Posts plugin page on WordPress.org.

The basic shortcode is [display-posts]

To only show the posts from our Favorites category, we will need to add a parameter. The full list of parameters that can be used is on the plugin’s website.

[display-posts category="favorites"]

We recommend you also review the official Display Post Tutorials, especially the Image Alignment options, to fine-tune the front-end display of your recent posts widget.

  1. Navigate to Appearance > Widgets.
  2. Add a Text Widget.
  3. Paste your desired shortcode in the widget.

display posts widget logic

The shortcode we used is:

[display-posts include_excerpt="true" excerpt_length="20" image_size="large" wrapper="div" wrapper_class="display-posts-listing image-top" category="favorites"]

This shortcode will display a 20 characters excerpt of each post, shows the featured image above the post content, and will only show posts in the category Favorites. On the front end, it looks like this:

Display Posts Widget display

Using Widget Logic to Display Recent Posts per Category

Either widget we just created will show everywhere the widget area is active. If you’d like to limit where the widget displays, you can add the Widget Logic plugin. It adds an extra field at the bottom of every widget, like shown below.

Widget Logic WordPress Plugin

The text field lets you use any of WordPress Core’s Conditional Tags, or any general PHP code, to select exactly where the widget is shown on your website. For example:

  • is_home() — only on the main blog page
  • is_page('about') — only on the About page
  • in_category('favorites') — only on the Favorites category page and posts
  • in_category( array('cat-1','cat-2') ) — only on the Cat-1 and Cat-2 category pages and posts

Display Recent Posts for Current Category

Now we have a way to display Recent Posts from a specific category, and we know how to display a widget only where we want. Using the plugins together allows you to show Recent Posts specific to the category the user is in, without creating multiple sidebars or using custom code in Core files.

For example, let’s say you have a category called Favorites. When a visitor is reading an article in the Favorites category you only want to show a Recent Post list with posts from the Favorites category. When the user changes to a different category, the Recent Post list will change to only show posts from that new category.

Step by Step Instructions

You will need to use either method to create multiple Recent Post widgets – one for each category you want Recent Posts to show on. Add them all to the same widget area, like the Primary Sidebar. Each Recent Post widget needs to include logic in the last input box to ensure the widget only displays where you want it to, otherwise it will display everywhere.

  1. Create a Recent Posts widget with the desired category selected, like shown in the first part of this article.
  2. Add in_category('favorites')to the Widget Logic input at the bottom of the widget panel, replacing favorites with your category name.
    Show Favorites Category posts
  3. View the front end of your site. You should only see the Recent Post list when you are in the category entered in Widget logic, and not anywhere else.
  4. Create another Recent Posts widget with a different category checked.
  5. Add in_category('news')to the Widget Logic input at the bottom of the widget panel, replacing news with your category name.
  6. Add it to the same widget area.
    Recent Post Extended Widgets
  7. View the front end of your site again. Switch between posts in the two categories to see the post list change.

You can repeat this process for as many categories as you need, there’s no limit on how many you can create.

Ready to Try?

As mentioned previously we strongly recommend you try these plugins in a staging environment to be sure they work with your theme and plugins, and to ensure you have a good understanding of the logic code before saving to a live site.

Test Post Widget Extended + Widget Logic

You can use BoldGrid’s Cloud WordPress test these plugins now with BoldGrid Crio, our latest WordPress theme for business.

Test Display Posts + Widget Logic

If you’d prefer to use shortcodes, you can test Display Posts and Widget Logic instead.

We hope you found this tutorial helpful and can use this information to gain greater control over your WordPress website. Let us know below if you have any questions.

 

SIGNUP FOR

BOLDGRID CENTRAL  

   200+ Design Templates + 1 Kick-ass SuperTheme
   6 WordPress Plugins + 2 Essential Services

Everything you need to build and manage WordPress websites in one Central place.

4 thoughts on “How to Display Recent Posts by Category in WordPress

  1. Unfortunately the [boldgrid_component type=”wp_rpwe_widget” opts=”…”] seems to break the options now. You have to use the shortcode without the boldgrid wrapper.

    • Hi Andy,

      I’m sorry to hear that you’re experiencing issues with your shortcode. My first thought is the syntax may be incomplete. The correct format of the shortcode should be like this:

      [boldgrid_component type="wp_rpwe_widget" opts="{'title':'Your Title','number':'5','show_date':'true'}"]

      Please ensure you are using the correct syntax and formatting. Also, make sure that the ‘Recent Posts Widget Extended’ plugin is installed and active as the “wp_rpwe_widget” component relies on it.

      If the issue persists, please create a new forum topic and provide more details about the problem you’re encountering and we’d be happy to assist you further.

  2. Thanks for this; however, a BoldGrid solution to the problem of displaying posts from selected categories – or a solution that is coordinated with BoldGrid so that changes in the solution or BoldGrid don’t break things down the road – would be preferred. Displaying posts by category is really a must-have for any site.

    • Hi Sam-
      Though the Recent Posts Widget isn’t a BoldGrid product, you’re right that it’s only one of many different ways you can show posts by category. WordPress-native solutions include the category archive pages, which you can find by navigating to Posts > Categories and selecting View under any of your categories. There is also a built-in Categories widget, and tons of other plugins that can accomplish the same thing depending on your goals.

Leave a Reply to Sam Cancel Reply

Your email address will not be published. Required fields are marked *