{"id":27781,"date":"2020-10-02T10:20:53","date_gmt":"2020-10-02T14:20:53","guid":{"rendered":"https:\/\/www.boldgrid.com\/support\/?p=27781"},"modified":"2021-09-13T11:27:29","modified_gmt":"2021-09-13T15:27:29","slug":"how-to-display-wordpress-recent-posts-by-category","status":"publish","type":"post","link":"https:\/\/www.boldgrid.com\/support\/wordpress-tutorials\/how-to-display-wordpress-recent-posts-by-category\/","title":{"rendered":"How to Display Recent Posts by Category in WordPress"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<?xml encoding=\"utf-8\" ?><html><body><p>The WordPress Core Recent Posts Widget is an easy way to display the most recent posts to your visitors. Unfortunately there isn&rsquo;t a way to only show recent posts from a specific category (or categories) without the use of a plugin.<\/p>\n<p>To find a solution, we did some testing using the <a href=\"https:\/\/wordpress.org\/plugins\/recent-posts-widget-extended\/\" target=\"_blank\" rel=\"noopener\">Recent Posts Widget Extended<\/a> and <a href=\"https:\/\/wordpress.org\/plugins\/widget-logic\/\" target=\"_blank\" rel=\"noopener\">Widget Logic<\/a> 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 <a href=\"\/wordpress-themes\/\">WordPress themes<\/a>.<\/p>\n<p>If you are using Twenty Twenty-One, you should consider using the <a href=\"https:\/\/wordpress.org\/plugins\/display-posts-shortcode\/\" target=\"_blank\" rel=\"noopener\">Display Posts plugin<\/a> to accomplish the same goal. Since this plugin uses shortcodes instead of a visual interface, it will work with Twenty Twenty-One.<\/p>\n<p>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.<\/p>\n<p>Please note that these plugins have a warning that it hasn&rsquo;t been tested with the most recent versions of WordPress. We <b>strongly<\/b> advise you test this plugin in a <a href=\"https:\/\/www.boldgrid.com\/free-wordpress-sites-demo\/\">WordPress staging<\/a> environment with your theme and current plugins to ensure compatibility.<\/p>\n<h2 id=\"create-a-recent-posts-by-category-widget\">Create a Recent Posts by Category Widget<\/h2>\n<h3 id=\"approach-1-use-recent-post-widget-extended-plugin\">Approach 1: Use Recent Post Widget Extended Plugin<\/h3>\n<p>The <a href=\"https:\/\/wordpress.org\/plugins\/recent-posts-widget-extended\/\">Recent Posts Widget Extended<\/a> 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.<\/p>\n<ol>\n<li>Navigate to <strong>Appearance &gt; Widgets<\/strong>.<\/li>\n<li>Select <strong>Recent Posts Extended<\/strong> from the widget list.<br>\n<a href=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/recent-posts-extended-widget.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-42445\" src=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/recent-posts-extended-widget.png\" alt=\"Recent Post Extended Widget\" width=\"330\" height=\"110\" srcset=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/recent-posts-extended-widget.png 330w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/recent-posts-extended-widget-300x100.png 300w\" sizes=\"auto, (max-width: 330px) 100vw, 330px\" \/><\/a><\/li>\n<li>Add the widget to the desired widget location, which will vary by theme.<\/li>\n<li>You can leave most settings as they are, but be sure to look at these:\n<ul>\n<li>Title<\/li>\n<li>Number of posts to show<\/li>\n<li>Display Thumbnail<\/li>\n<li>Display Readmore<\/li>\n<\/ul>\n<\/li>\n<li>In the <strong>Limit to Category<\/strong> box, check the category or categories you&rsquo;d like to display posts from.<br>\n<a href=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/recent-posts-extended-plugin-options-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42455 size-full\" src=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/recent-posts-extended-plugin-options-2.jpg\" alt=\"Recent Posts Extended plugin options\" width=\"776\" height=\"842\" srcset=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/recent-posts-extended-plugin-options-2.jpg 776w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/recent-posts-extended-plugin-options-2-276x300.jpg 276w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/recent-posts-extended-plugin-options-2-768x833.jpg 768w\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" \/><\/a><\/li>\n<li>Navigate to the front end of your website to see your new widget!<br>\n<a href=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/favorite-post-list.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42438 size-medium\" src=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/favorite-post-list-273x300.png\" alt=\"Post List in WordPress\" width=\"273\" height=\"300\" srcset=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/favorite-post-list-273x300.png 273w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/favorite-post-list.png 328w\" sizes=\"auto, (max-width: 273px) 100vw, 273px\" \/><\/a><\/li>\n<\/ol>\n<p>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.<\/p>\n<h3 id=\"approach-2-use-display-posts-plugin\">Approach 2: Use Display Posts Plugin<\/h3>\n<p>You can also use the Display Posts plugin to create a post list by category. You will use a shortcode to choose what displays &ndash; excerpt, image, read more link, etc &ndash; using the instructions on the <a href=\"https:\/\/wordpress.org\/plugins\/display-posts-shortcode\/\" target=\"_blank\" rel=\"noopener\">Display Posts plugin<\/a> page on WordPress.org.<\/p>\n<p>The basic shortcode is <code>[display-posts]<\/code><\/p>\n<p>To only show the posts from our Favorites category, we will need to add a parameter. The <a href=\"https:\/\/displayposts.com\/docs\/parameters\/#display-parameters\" target=\"_blank\" rel=\"noopener\">full list of parameters<\/a> that can be used is on the plugin&rsquo;s website.<\/p>\n<p><code>[display-posts category=\"favorites\"]<\/code><\/p>\n<p>We recommend you also review the official <a href=\"https:\/\/displayposts.com\/tutorials\/\" target=\"_blank\" rel=\"noopener\">Display Post Tutorials<\/a>, especially the <a href=\"https:\/\/displayposts.com\/2019\/01\/04\/image-alignment\/\" target=\"_blank\" rel=\"noopener\">Image Alignment<\/a> options, to fine-tune the front-end display of your recent posts widget.<\/p>\n<ol>\n<li>Navigate to <strong>Appearance &gt; Widgets<\/strong>.<\/li>\n<li>Add a <strong>Text<\/strong> Widget.<\/li>\n<li>Paste your desired shortcode in the widget.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2021\/09\/display-posts-widget-logic.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42721\" src=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2021\/09\/display-posts-widget-logic.png\" alt=\"display posts widget logic\" width=\"400\" height=\"566\" srcset=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2021\/09\/display-posts-widget-logic.png 464w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2021\/09\/display-posts-widget-logic-212x300.png 212w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>The shortcode we used is:<\/p>\n<p><code>[display-posts include_excerpt=\"true\" excerpt_length=\"20\" image_size=\"large\" wrapper=\"div\" wrapper_class=\"display-posts-listing image-top\" category=\"favorites\"]<\/code><\/p>\n<p>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:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2021\/09\/display-posts-widget.png\" alt=\"Display Posts Widget display\" width=\"329\" height=\"847\"><\/p>\n<h2 id=\"using-widget-logic-to-display-recent-posts-per-category\">Using Widget Logic to Display Recent Posts per Category<\/h2>\n<p>Either widget we just created will show everywhere the widget area is active. If you&rsquo;d like to limit where the widget displays, you can add the <a href=\"https:\/\/wordpress.org\/plugins\/widget-logic\/\">Widget Logic<\/a> plugin. It adds an extra field at the bottom of every widget, like shown below.<\/p>\n<p><a href=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/wiget-logic.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42456 size-full\" src=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/wiget-logic-e1630697913522.jpg\" alt=\"Widget Logic WordPress Plugin\" width=\"775\" height=\"797\" srcset=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/wiget-logic-e1630697913522.jpg 775w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/wiget-logic-e1630697913522-292x300.jpg 292w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/wiget-logic-e1630697913522-768x790.jpg 768w\" sizes=\"auto, (max-width: 775px) 100vw, 775px\" \/><\/a><\/p>\n<p>The text field lets you use any of WordPress Core&rsquo;s <a href=\"https:\/\/codex.wordpress.org\/Conditional_Tags\" rel=\"nofollow\">Conditional Tags<\/a>, or any general PHP code, to select exactly where the widget is shown on your website. For example:<\/p>\n<ul>\n<li><code>is_home()<\/code> &mdash; only on the main blog page<\/li>\n<li><code>is_page('about')<\/code> &mdash; only on the About page<\/li>\n<li><code>in_category('favorites')<\/code> &mdash; only on the Favorites category page and posts<\/li>\n<li><code>in_category( array('cat-1','cat-2') )<\/code> &mdash; only on the Cat-1 and Cat-2 category pages and posts<\/li>\n<\/ul>\n<h2 id=\"display-recent-posts-for-current-category\">Display Recent Posts for Current Category<\/h2>\n<p>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.<\/p>\n<p>For example, let&rsquo;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.<\/p>\n<h3 id=\"step-by-step-instructions\">Step by Step Instructions<\/h3>\n<p>You will need to use either method to create multiple Recent Post widgets &ndash; 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.<\/p>\n<ol>\n<li>Create a Recent Posts widget with the desired category selected, like shown in the first part of this article.<\/li>\n<li>Add <code>in_category('favorites')<\/code>to the Widget Logic input at the bottom of the widget panel, replacing <em>favorites<\/em> with your category name.<br>\n<a href=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/widget-logic-favorites.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-42460\" src=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/widget-logic-favorites.png\" alt=\"Show Favorites Category posts\" width=\"191\" height=\"90\"><\/a><\/li>\n<li>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.<\/li>\n<li>Create another Recent Posts widget with a different category checked.<\/li>\n<li>Add <code>in_category('news')<\/code>to the Widget Logic input at the bottom of the widget panel, replacing <em>news<\/em> with your category name.<\/li>\n<li>Add it to the same widget area.<br>\n<a href=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/multiple-recent-post-extended-widgets.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-42440\" src=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/multiple-recent-post-extended-widgets.png\" alt=\"Recent Post Extended Widgets\" width=\"328\" height=\"151\" srcset=\"https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/multiple-recent-post-extended-widgets.png 491w, https:\/\/www.boldgrid.com\/support\/wp-content\/uploads\/2020\/10\/multiple-recent-post-extended-widgets-300x138.png 300w\" sizes=\"auto, (max-width: 328px) 100vw, 328px\" \/><\/a><\/li>\n<li>View the front end of your site again. Switch between posts in the two categories to see the post list change.<\/li>\n<\/ol>\n<p>You can repeat this process for as many categories as you need, there&rsquo;s no limit on how many you can create.<\/p>\n<h2 id=\"ready-to-try\">Ready to Try?<\/h2>\n<p>As mentioned previously we <strong>strongly<\/strong> 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.<\/p>\n<h3 id=\"test-post-widget-extended--widget-logic\">Test Post Widget Extended + Widget Logic<\/h3>\n<p>You can use BoldGrid&rsquo;s Cloud WordPress <a href=\"https:\/\/www.boldgrid.com\/central\/cloud-wordpress\/try?theme=crio&amp;plugins=widget-logic,recent-posts-widget-extended\">test these plugins now<\/a> with BoldGrid Crio, our latest <a href=\"https:\/\/www.boldgrid.com\/crio-wordpress-theme-for-business\/\">WordPress theme for business<\/a>.<\/p>\n<h3 id=\"test-display-posts--widget-logic\">Test Display Posts + Widget Logic<\/h3>\n<p>If you&rsquo;d prefer to use shortcodes, you can <a href=\"https:\/\/www.boldgrid.com\/central\/cloud-wordpress\/try?theme=crio&amp;plugins=widget-logic,\/display-posts-shortcode\">test Display Posts and Widget Logic<\/a> instead.<\/p>\n<p>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.<\/p>\n<\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>The WordPress Core Recent Posts Widget is an easy way to display the most recent posts to your visitors. Unfortunately there isn&rsquo;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 [&hellip;]<\/p>\n","protected":false},"author":215,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"bgseo_title":"How to Display Recent Posts by Category in WordPress","bgseo_description":"Learn how to display recent posts by category in WordPress and only show recent posts for the current category by limiting where the widget displays.","bgseo_robots_index":"index","bgseo_robots_follow":"follow","footnotes":""},"categories":[151],"tags":[],"class_list":["post-27781","post","type-post","status-publish","format-standard","hentry","category-wordpress-tutorials"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts\/27781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/users\/215"}],"replies":[{"embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/comments?post=27781"}],"version-history":[{"count":22,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts\/27781\/revisions"}],"predecessor-version":[{"id":42723,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/posts\/27781\/revisions\/42723"}],"wp:attachment":[{"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/media?parent=27781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/categories?post=27781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.boldgrid.com\/support\/wp-json\/wp\/v2\/tags?post=27781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}