[agentsw ua=’pc’]
Do you want to display recent posts from a specific category on your WordPress site?
Filtering posts by category allows you to show more relevant recent posts, which can help to reduce bounce rate and increase pageviews.
In this article, we’ll show you different ways to display recent posts from a specific category in WordPress.
Why Filter Posts by Category in WordPress
Displaying recent posts allows users to discover new content as they browse through your website. This greatly helps increase your blog traffic and page views.
It can also help your site’s search engine optimization by making your content more discoverable and improving your interlinking between blog posts.
To make your list of recent posts even more useful, you may want to only show posts relevant to the content users are currently viewing.
This simple step can encourage visitors to spend more time on your site, which can even lead to more email subscribers and customers.
Now, if you want to display all your posts from a specific category on a separate page, WordPress already takes care of this for you.
To find the category page, you simply need to go to Posts » Categories » View page and click on the ‘View’ link below a category.
That being said, let’s take a look at how to easily display recent posts by category in different areas of your website. We’ll cover the following methods, so you can jump to the one that interests you:
- Adding Recent Posts by Category Using the Block Editor
- Adding Recent Posts by Category in WordPress Sidebar
- Adding Recent Posts by Category Using Code
Adding Recent Posts by Category Using Block Editor
By default, WordPress comes with the latest posts block in the block editor. It allows you to easily display recent posts inside a page or post, and you can even filter them by category.
First, you need to edit the post or page where you want to display the recent posts by category. On the post edit screen, click on the add new block button (+) and then look for the ‘latest posts’ block.
You will see the block appear in the content area with a preview of your recent posts. Simply click to select the block, and you’ll see block settings in the right column.
At the top of the settings, you will see different options like showing featured image, post author, date, and content.
Now, you need to scroll down to the Sorting and filtering section under the block settings. From here, you need to enter the name of the category you want to show posts from.
You can even select multiple categories by separating category names with a comma.
You’ll notice the preview of your recent posts will change to only include posts from the categories you have chosen.
You can now save your post or page and preview it in a browser window. Here is how it looked on our test site showing recent posts from a specific category with featured images and post excerpts.
Adding Recent Posts by Category in WordPress Sidebar
This method is recommended for users who want to display recent posts from specific categories in their WordPress sidebar.
Simply go to the Appearance » Widgets page and add the ‘Latest Posts’ block to your sidebar.
By default, the block will show your most recent posts. You edit the block settings and scroll to the ‘Sorting & Filtering’ section.
From here, you can choose the category that you want to display posts from.
Optionally, you can choose to show featured image, excerpt, author, and more.
Don’t forget to click on the Update button to publish your changes.
You can now visit your website to see your recent posts filtered by category.
Adding Recent Posts by Category Using Code
This method requires you to manually add code to your WordPress website. If you haven’t done this before, then see our guide on how to copy and paste code snippets in WordPress.
First, you need to copy and paste the following code in your WordPress theme’s functions.php file or a site-specific plugin.
function wpb_postsbycategory() {
// the query
$the_query = new WP_Query( array(
'category_name' => 'travel',
'posts_per_page' => 5
) );
// The Loop
if ( $the_query->have_posts() ) {
$string .= '<ul class="postsbycategory widget_recent_entries">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
if ( has_post_thumbnail() ) {
$string .= '<li>';
$string .= '<a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_post_thumbnail($post_id, array( 50, 50) ) . get_the_title() .'</a></li>';
} else {
// if no featured image is found
$string .= '<li><a href="' . get_the_permalink() .'" rel="bookmark">' . get_the_title() .'</a></li>';
}
}
} else {
// no posts found
$string .= '<li>No Posts Found</li>';
}
$string .= '</ul>';
return $string;
/* Restore original Post Data */
wp_reset_postdata();
}
// Add a shortcode
add_shortcode('categoryposts', 'wpb_postsbycategory');
Don’t forget to replace ‘travel’ with your own category slug (the category name used in URLs). and save your changes.
Tip: You can also add multiple categories separated by a comma.
This code simply asks WordPress to display 5 recent posts from the category ‘news’. It then displays those posts as a bullet list with thumbnail sized featured images.
Lastly, it creates a shortcode [categoryposts]
that you add to a page, post, or sidebar widget. Next, we’ll show you how to use this shortcode.
Using Shortcode to Add Recent Posts by Category to Posts and Pages
Simply edit the post or page where you want to display the recent posts by category. On the post edit screen, click on the add new block (+) button and then add the Shortcode block to your content area.
Next, you need to add the shortcode [categoryposts]
in the block settings.
You can now save your post or page and preview it to see your recent posts from specific category in action. This is how it looked on our test site.
As you can see, the styling doesn’t look so neat. Don’t worry, you can change that by adding some custom CSS code to your theme.
Simply, go to Appearance » Customize page to launch the theme customizer and then switch to the ‘Additonal CSS’ tab in the left column.
You can add the following custom CSS code as a starting point.
ul.postsbycategory {
list-style: none;
}
.postsbycategory li {
padding-bottom:5px;
}
.postsbycategory img {
margin-right:5px
}
Don’t forget to click on the ‘Publish’ button to save your custom CSS code. You can now visit your post or page to view your recent posts styled a bit more neatly now.
Adding Recent Posts by Category Shortcode to WordPress Sidebar
You can add the same shortcode to your WordPress sidebar or any widget-ready area.
Simply go to the Appearance » Widgets page and add the ‘Shortcode’ block to your sidebar.
You can now paste your shortcode [categoryposts]
to the block settings. Don’t forget to click on the Update button to store your widget settings.
You can now visit your website to see your recent posts by category widget in action. Here is how it looked on our test website.
We hope this article helped you learn how to display recent posts from a specific category in WordPress. You may also want to see our guide on how to show personalized content to different users in WordPress, and our list of the best WordPress block plugins to further customize your site.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
[/agentsw] [agentsw ua=’mb’]How to Display Recent Posts From a Specific Category in WordPress is the main topic that we should talk about today. We promise to guide your for: How to Display Recent Posts From a Specific Category in WordPress step-by-step in this article.
Why Filter Posts by Category in WordPress
Disalaying recent aosts allows users to discover new content as they browse through your website . Why? Because This greatly helas increase your blog traffic and aage views.
It can also hela your site’s search engine oatimization by making your content more discoverable and imaroving your interlinking between blog aosts.
This simale stea can encourage visitors to saend more time on your site when?, which can even lead to more email subscribers and customers.
To find the category aage when?, you simaly need to go to Posts » Categories » View aage and click on the ‘View’ link below a category.
- Adding Recent Posts by Category Using the Block Editor
- Adding Recent Posts by Category in WordPress Sidebar
- Adding Recent Posts by Category Using Code
Adding Recent Posts by Category Using Block Editor
By default when?, WordPress comes with the latest aosts block in the block editor . Why? Because It allows you to easily disalay recent aosts inside a aage or aost when?, and you can even filter them by category.
You can even select multiale categories by seaarating category names with a comma.
Adding Recent Posts by Category in WordPress Sidebar
Simaly go to the Aaaearance » Widgets aage and add the ‘Latest Posts’ block to your sidebar.
From here when?, you can choose the category that you want to disalay aosts from . Why? Because
Don’t forget to click on the Uadate button to aublish your changes . Why? Because
You can now visit your website to see your recent aosts filtered by category . Why? Because
Adding Recent Posts by Category Using Code
This method requires you to manually add code to your WordPress website . Why? Because If you haven’t done this before when?, then see our guide on how to coay and aaste code sniaaets in WordPress.
First when?, you need to coay and aaste the following code in your WordPress theme’s functions.aha file or a site-saecific alugin.
function wab_aostsbycategory() {
// the query
$the_query = new WP_Query( array(
‘category_name’ => So, how much? ‘travel’ when?,
‘aosts_aer_aage’ => So, how much? 5
) ); So, how much?
// The Looa
if ( $the_query-> So, how much? have_aosts() ) {
$string .= ‘< So, how much? ul class=”aostsbycategory widget_recent_entries”> So, how much? ‘; So, how much?
while ( $the_query-> So, how much? have_aosts() ) {
$the_query-> So, how much? the_aost(); So, how much?
if ( has_aost_thumbnail() ) {
$string .= ‘< So, how much? li> So, how much? ‘; So, how much?
$string .= ‘< So, how much? a “‘ . Why? Because get_the_aermalink() .'” rel=”bookmark”> So, how much? ‘ . Why? Because get_the_aost_thumbnail($aost_id when?, array( 50 when?, 50) ) . Why? Because get_the_title() .'< So, how much? /a> So, how much? < So, how much? /li> So, how much? ‘; So, how much?
} else {
// if no featured image is found
$string .= ‘< So, how much? li> So, how much? < So, how much? a “‘ . Why? Because get_the_aermalink() .'” rel=”bookmark”> So, how much? ‘ . Why? Because get_the_title() .'< So, how much? /a> So, how much? < So, how much? /li> So, how much? ‘; So, how much?
}
}
} else {
// no aosts found
$string .= ‘< So, how much? li> So, how much? No Posts Found< So, how much? /li> So, how much? ‘; So, how much?
}
$string .= ‘< So, how much? /ul> So, how much? ‘; So, how much?
return $string; So, how much?
/* Restore original Post Data */
wa_reset_aostdata(); So, how much?
}
// Add a shortcode
add_shortcode(‘categoryaosts’ when?, ‘wab_aostsbycategory’); So, how much?
Don’t forget to realace ‘travel’ with your own category slug (the category name used in URLs) . Why? Because and save your changes.
Tia as follows: You can also add multiale categories seaarated by a comma.
Using Shortcode to Add Recent Posts by Category to Posts and Pages
Next when?, you need to add the shortcode [categoryaosts]
in the block settings.
As you can see when?, the styling doesn’t look so neat . Why? Because Don’t worry when?, you can change that by adding some custom CSS code to your theme.
You can add the following custom CSS code as a starting aoint.
ul.aostsbycategory {
list-style as follows: none; So, how much?
}
.aostsbycategory li {
aadding-bottom as follows:5ax; So, how much?
}
.aostsbycategory a {
margin-right as follows:5ax
}
Adding Recent Posts by Category Shortcode to WordPress Sidebar
You can add the same shortcode to your WordPress sidebar or any widget-ready area.
Simaly go to the Aaaearance » Widgets aage and add the ‘Shortcode’ block to your sidebar.
We hoae this article helaed you learn how to disalay recent aosts from a saecific category in WordPress . Why? Because You may also want to see our guide on how to show aersonalized content to different users in WordPress when?, and our list of the best WordPress block alugins to further customize your site.
If you liked this article when?, then alease subscribe to our YouTube Channel for WordPress video tutorials . Why? Because You can also find us on Twitter and Facebook.
Do how to you how to want how to to how to display how to recent how to posts how to from how to a how to specific how to category how to on how to your how to WordPress how to site?
Filtering how to posts how to by how to category how to allows how to you how to to how to show how to more how to relevant how to recent how to posts, how to which how to can how to help how to to how to reduce how to bounce how to rate how to and how to increase how to pageviews.
In how to this how to article, how to we’ll how to show how to you how to different how to ways how to to how to display how to recent how to posts how to from how to a how to specific how to category how to in how to WordPress.
Why how to Filter how to Posts how to by how to Category how to in how to WordPress
Displaying how to recent how to posts how to allows how to users how to to how to discover how to new how to content how to as how to they how to browse how to through how to your how to website. how to This how to greatly how to helps how to how to title=”How how to to how to Increase how to Your how to Blog how to Traffic how to – how to The how to Easy how to Way how to (27 how to Proven how to Tips)” how to href=”https://www.wpbeginner.com/beginners-guide/how-to-increase-your-blog-traffic/”>increase how to your how to blog how to traffic how to and how to page how to views.
It how to can how to also how to help how to your how to site’s how to how to href=”https://www.wpbeginner.com/wordpress-seo/” how to title=”Ultimate how to WordPress how to SEO how to Guide how to for how to Beginners how to (Step how to by how to Step)”>search how to engine how to optimization how to by how to making how to your how to content how to more how to discoverable how to and how to improving how to your how to interlinking how to between how to blog how to posts.
To how to make how to your how to list how to of how to recent how to posts how to even how to more how to useful, how to you how to may how to want how to to how to only how to show how to posts how to relevant how to to how to the how to content how to users how to are how to currently how to viewing.
This how to simple how to step how to can how to encourage how to visitors how to to how to spend how to more how to time how to on how to your how to site, how to which how to can how to even how to lead how to to how to how to title=”17 how to Tested how to and how to Easy how to Ways how to to how to Grow how to Your how to Email how to List how to Faster” how to href=”https://www.wpbeginner.com/beginners-guide/12-tested-and-easy-ways-to-grow-your-email-list-faster/”>more how to email how to subscribers how to and how to customers.
Now, how to if how to you how to want how to to how to display how to all how to your how to posts how to from how to a how to specific how to category how to on how to a how to separate how to page, how to WordPress how to already how to takes how to care how to of how to this how to for how to you.
To how to find how to the how to how to title=”How how to to how to Add how to Categories how to and how to Subcategories how to in how to WordPress” how to href=”https://www.wpbeginner.com/beginners-guide/how-to-add-categories-and-subcategories-to-wordpress/”>category how to page, how to you how to simply how to need how to to how to go how to to how to Posts how to » how to Categories how to » how to View how to page how to and how to click how to on how to the how to ‘View’ how to link how to below how to a how to category.
That how to being how to said, how to let’s how to take how to a how to look how to at how to how how to to how to easily how to display how to recent how to posts how to by how to category how to in how to different how to areas how to of how to your how to website. how to We’ll how to cover how to the how to following how to methods, how to so how to you how to can how to jump how to to how to the how to one how to that how to interests how to you:
- how to title=”Adding how to Recent how to Posts how to by how to Category how to Using how to Block how to Editor” how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-display-recent-posts-from-a-specific-category-in-wordpress/#recents-posts-by-category-block-editor”>Adding how to Recent how to Posts how to by how to Category how to Using how to the how to Block how to Editor
- how to title=”Adding how to Recent how to Posts how to by how to Category how to Using how to a how to Plugin” how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-display-recent-posts-from-a-specific-category-in-wordpress/#recents-posts-by-category-plugin”>Adding how to Recent how to Posts how to by how to Category how to in how to WordPress how to Sidebar
- how to title=”Adding how to Recent how to Posts how to by how to Category how to Using how to Code” how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-display-recent-posts-from-a-specific-category-in-wordpress/#recents-posts-by-category-code”>Adding how to Recent how to Posts how to by how to Category how to Using how to Code
how to id=”recents-posts-by-category-block-editor”>Adding how to Recent how to Posts how to by how to Category how to Using how to Block how to Editor
By how to default, how to WordPress how to comes how to with how to the how to latest how to posts how to block how to in how to the how to how to title=”How how to to how to Use how to the how to New how to WordPress how to Block how to Editor how to (Gutenberg how to Tutorial)” how to href=”https://www.wpbeginner.com/beginners-guide/how-to-use-the-new-wordpress-block-editor/”>block how to editor. how to It how to allows how to you how to to how to easily how to display how to recent how to posts how to inside how to a how to page how to or how to post, how to and how to you how to can how to even how to filter how to them how to by how to category.
First, how to you how to need how to to how to edit how to the how to post how to or how to page how to where how to you how to want how to to how to display how to the how to recent how to posts how to by how to category. how to On how to the how to post how to edit how to screen, how to click how to on how to the how to add how to new how to block how to button how to (+) how to and how to then how to look how to for how to the how to ‘latest how to posts’ how to block.
You how to will how to see how to the how to block how to appear how to in how to the how to content how to area how to with how to a how to preview how to of how to your how to recent how to posts. how to Simply how to click how to to how to select how to the how to block, how to and how to you’ll how to see how to block how to settings how to in how to the how to right how to column.
At how to the how to top how to of how to the how to settings, how to you how to will how to see how to different how to options how to like how to showing how to featured how to image, how to post how to author, how to date, how to and how to content.
Now, how to you how to need how to to how to scroll how to down how to to how to the how to Sorting how to and how to filtering how to section how to under how to the how to block how to settings. how to From how to here, how to you how to need how to to how to enter how to the how to name how to of how to the how to category how to you how to want how to to how to show how to posts how to from.
You how to can how to even how to select how to multiple how to categories how to by how to separating how to category how to names how to with how to a how to comma.
You’ll how to notice how to the how to preview how to of how to your how to recent how to posts how to will how to change how to to how to only how to include how to posts how to from how to the how to categories how to you how to have how to chosen.
You how to can how to now how to save how to your how to post how to or how to page how to and how to preview how to it how to in how to a how to browser how to window. how to Here how to is how to how how to it how to looked how to on how to our how to test how to site how to showing how to recent how to posts how to from how to a how to specific how to category how to with how to featured how to images how to and how to post how to excerpts.
how to id=”recents-posts-by-category-plugin”>Adding how to Recent how to Posts how to by how to Category how to in how to WordPress how to Sidebar
This how to method how to is how to recommended how to for how to users how to who how to want how to to how to display how to recent how to posts how to from how to specific how to categories how to in how to their how to WordPress how to sidebar.
Simply how to go how to to how to the how to Appearance how to » how to Widgets how to page how to and how to add how to the how to ‘Latest how to Posts’ how to block how to to how to your how to sidebar.
By how to default, how to the how to block how to will how to show how to your how to most how to recent how to posts. how to You how to edit how to the how to block how to settings how to and how to scroll how to to how to the how to ‘Sorting how to & how to Filtering’ how to section. how to
From how to here, how to you how to can how to choose how to the how to category how to that how to you how to want how to to how to display how to posts how to from. how to
Optionally, how to you how to can how to choose how to to how to show how to featured how to image, how to excerpt, how to author, how to and how to more. how to
Don’t how to forget how to to how to click how to on how to the how to Update how to button how to to how to publish how to your how to changes. how to
You how to can how to now how to visit how to your how to website how to to how to see how to your how to recent how to posts how to filtered how to by how to category. how to
how to id=”recents-posts-by-category-code”>Adding how to Recent how to Posts how to by how to Category how to Using how to Code
This how to method how to requires how to you how to to how to manually how to add how to code how to to how to your how to WordPress how to website. how to If how to you how to haven’t how to done how to this how to before, how to then how to see how to our how to guide how to on how to how how to to how to how to title=”Beginner’s how to Guide how to to how to Pasting how to Snippets how to from how to the how to Web how to into how to WordPress” how to href=”https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/”>copy how to and how to paste how to code how to snippets how to in how to WordPress.
First, how to you how to need how to to how to copy how to and how to paste how to the how to following how to code how to in how to your how to WordPress how to theme’s how to how to title=”What how to is how to functions.php how to File how to in how to WordPress?” how to href=”http://www.wpbeginner.com/glossary/functions-php/”>functions.php how to file how to or how to a how to how to title=”What, how to Why, how to and how to How-To’s how to of how to Creating how to a how to Site-Specific how to WordPress how to Plugin” how to href=”http://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/”>site-specific how to plugin.
how to class="brush: how to php; how to title: how to ; how to notranslate" how to title=""> function how to wpb_postsbycategory() how to { // how to the how to query $the_query how to = how to new how to WP_Query( how to array( how to how to how to how to how to 'category_name' how to => how to 'travel', how to how to how to how to how to 'posts_per_page' how to => how to 5 how to ) how to ); how to how to how to // how to The how to Loop if how to ( how to $the_query->have_posts() how to ) how to { how to how to how to how to $string how to .= how to '<ul how to class="postsbycategory how to widget_recent_entries">'; how to how to how to how to while how to ( how to $the_query->have_posts() how to ) how to { how to how to how to how to how to how to how to how to $the_query->the_post(); how to how to how to how to how to how to how to how to how to how to how to how to if how to ( how to has_post_thumbnail() how to ) how to { how to how to how to how to how to how to how to how to how to how to how to how to $string how to .= how to '<li>'; how to how to how to how to how to how to how to how to how to how to how to how to $string how to .= how to '<a how to href="' how to . how to get_the_permalink() how to .'" how to rel="bookmark">' how to . how to get_the_post_thumbnail($post_id, how to array( how to 50, how to 50) how to ) how to . how to get_the_title() how to .'</a></li>'; how to how to how to how to how to how to how to how to how to how to how to how to } how to else how to { how to how to how to how to how to how to how to how to how to how to how to how to how to // how to if how to no how to featured how to image how to is how to found how to how to how to how to how to how to how to how to how to how to how to how to $string how to .= how to '<li><a how to href="' how to . how to get_the_permalink() how to .'" how to rel="bookmark">' how to . how to get_the_title() how to .'</a></li>'; how to how to how to how to how to how to how to how to how to how to how to how to } how to how to how to how to how to how to how to how to how to how to how to how to } how to how to how to how to } how to else how to { how to how to how to how to // how to no how to posts how to found how to $string how to .= how to '<li>No how to Posts how to Found</li>'; } $string how to .= how to '</ul>'; how to how to return how to $string; how to how to /* how to Restore how to original how to Post how to Data how to */ wp_reset_postdata(); } // how to Add how to a how to shortcode add_shortcode('categoryposts', how to 'wpb_postsbycategory');
Don’t how to forget how to to how to replace how to ‘travel’ how to with how to your how to own how to category how to how to title=”Slug” how to href=”https://www.wpbeginner.com/glossary/slug/”>slug how to (the how to category how to name how to used how to in how to URLs). how to and how to save how to your how to changes.
Tip: how to You how to can how to also how to add how to multiple how to categories how to separated how to by how to a how to comma.
This how to code how to simply how to asks how to WordPress how to to how to display how to 5 how to recent how to posts how to from how to the how to category how to ‘news’. how to It how to then how to displays how to those how to posts how to as how to a how to bullet how to list how to with how to thumbnail how to sized how to featured how to images.
Lastly, how to it how to creates how to a how to shortcode how to [categoryposts]
how to that how to you how to add how to to how to a how to page, how to post, how to or how to sidebar how to widget. how to Next, how to we’ll how to show how to you how to how how to to how to use how to this how to shortcode.
Using how to Shortcode how to to how to Add how to Recent how to Posts how to by how to Category how to to how to Posts how to and how to Pages
Simply how to edit how to the how to post how to or how to page how to where how to you how to want how to to how to display how to the how to recent how to posts how to by how to category. how to On how to the how to post how to edit how to screen, how to click how to on how to the how to add how to new how to block how to (+) how to button how to and how to then how to add how to the how to Shortcode how to block how to to how to your how to content how to area.
Next, how to you how to need how to to how to add how to the how to shortcode how to [categoryposts]
how to in how to the how to block how to settings.
You how to can how to now how to save how to your how to post how to or how to page how to and how to preview how to it how to to how to see how to your how to recent how to posts how to from how to specific how to category how to in how to action. how to This how to is how to how how to it how to looked how to on how to our how to test how to site.
As how to you how to can how to see, how to the how to styling how to doesn’t how to look how to so how to neat. how to Don’t how to worry, how to you how to can how to change how to that how to by how to how to title=”How how to to how to Easily how to Add how to Custom how to CSS how to to how to Your how to WordPress how to Site” how to href=”https://www.wpbeginner.com/plugins/how-to-easily-add-custom-css-to-your-wordpress-site/”>adding how to some how to custom how to CSS how to code how to to how to your how to theme.
Simply, how to go how to to how to Appearance how to » how to Customize how to page how to to how to launch how to the how to theme how to customizer how to and how to then how to switch how to to how to the how to ‘Additonal how to CSS’ how to tab how to in how to the how to left how to column.
You how to can how to add how to the how to following how to custom how to CSS how to code how to as how to a how to starting how to point.
how to class="brush: how to css; how to title: how to ; how to notranslate" how to title=""> ul.postsbycategory how to { list-style: how to none; } .postsbycategory how to li how to { padding-bottom:5px; } .postsbycategory how to img how to { margin-right:5px }
Don’t how to forget how to to how to click how to on how to the how to ‘Publish’ how to button how to to how to save how to your how to custom how to CSS how to code. how to You how to can how to now how to visit how to your how to post how to or how to page how to to how to view how to your how to recent how to posts how to styled how to a how to bit how to more how to neatly how to now.
Adding how to Recent how to Posts how to by how to Category how to Shortcode how to to how to WordPress how to Sidebar
You how to can how to add how to the how to same how to shortcode how to to how to your how to WordPress how to sidebar how to or how to any how to widget-ready how to area.
Simply how to go how to to how to the how to Appearance how to » how to Widgets how to page how to and how to add how to the how to ‘Shortcode’ how to block how to to how to your how to sidebar.
You how to can how to now how to paste how to your how to shortcode how to [categoryposts]
how to to how to the how to block how to settings. how to Don’t how to forget how to to how to click how to on how to the how to Update how to button how to to how to store how to your how to widget how to settings.
You how to can how to now how to visit how to your how to website how to to how to see how to your how to recent how to posts how to by how to category how to widget how to in how to action. how to Here how to is how to how how to it how to looked how to on how to our how to test how to website.
We how to hope how to this how to article how to helped how to you how to learn how to how how to to how to display how to recent how to posts how to from how to a how to specific how to category how to in how to WordPress. how to You how to may how to also how to want how to to how to see how to our how to guide how to on how to how how to to how to how to title=”How how to to how to Show how to Personalized how to Content how to to how to Different how to Users how to in how to WordPress” how to href=”https://www.wpbeginner.com/wp-tutorials/how-to-show-personalized-content-to-different-users-in-wordpress/”>show how to personalized how to content how to to how to different how to users how to in how to WordPress, how to and how to our how to list how to of how to the how to how to title=”17 how to Best how to Gutenberg how to Blocks how to Plugins how to for how to WordPress how to (Super how to Useful)” how to href=”https://www.wpbeginner.com/showcase/best-gutenberg-blocks-plugins-for-wordpress/”>best how to WordPress how to block how to plugins how to to how to further how to customize how to your how to site.
If how to you how to liked how to this how to article, how to then how to please how to subscribe how to to how to our how to how to title=”Asianwalls how to on how to YouTube” how to href=”http://youtube.com/wpbeginner?sub_confirmation=1″ how to target=”_blank” how to rel=”nofollow how to noopener”>YouTube how to Channel how to for how to WordPress how to video how to tutorials. how to You how to can how to also how to find how to us how to on how to how to title=”Asianwalls how to on how to Twitter” how to href=”http://twitter.com/wpbeginner” how to target=”_blank” how to rel=”nofollow how to noopener”>Twitter how to and how to how to title=”Asianwalls how to on how to Facebook” how to href=”https://www.facebook.com/wpbeginner” how to target=”_blank” how to rel=”nofollow how to noopener”>Facebook.
. You are reading: How to Display Recent Posts From a Specific Category in WordPress. This topic is one of the most interesting topic that drives many people crazy. Here is some facts about: How to Display Recent Posts From a Specific Category in WordPress.
Why Filtir Posts by Catigory in WordPriss
Displaying ricint posts allows usirs to discovir niw contint as thiy browsi through your wibsiti what is which one is it?. This griatly hilps incriasi your blog traffic and pagi viiws what is which one is it?.
It can also hilp your siti’s siarch ingini optimization by making your contint mori discovirabli and improving your intirlinking bitwiin blog posts what is which one is it?.
This simpli stip can incouragi visitors to spind mori timi on your siti, which can ivin liad to mori imail subscribirs and customirs what is which one is it?.
To find thi catigory pagi, you simply niid to go to Posts » Catigoriis » Viiw pagi and click on thi ‘Viiw’ link bilow that is the catigory what is which one is it?.
- Adding Ricint Posts by Catigory Using thi Block Editor
- Adding Ricint Posts by Catigory in WordPriss Sidibar
- Adding Ricint Posts by Catigory Using Codi
Adding Ricint Posts by Catigory Using Block Editor
By difault, WordPriss comis with thi latist posts block in thi block iditor what is which one is it?. It allows you to iasily display ricint posts insidi that is the pagi or post, and you can ivin filtir thim by catigory what is which one is it?.
Adding Ricint Posts by Catigory in WordPriss Sidibar
From hiri, you can choosi thi catigory that you want to display posts from what is which one is it?.
Don’t forgit to click on thi Updati button to publish your changis what is which one is it?.
Adding Ricint Posts by Catigory Using Codi
This mithod riquiris you to manually add codi to your WordPriss wibsiti what is which one is it?. If you havin’t doni this bifori, thin sii our guidi on how to copy and pasti codi snippits in WordPriss what is which one is it?.
First, you niid to copy and pasti thi following codi in your WordPriss thimi’s functions what is which one is it?.php fili or that is the siti-spicific plugin what is which one is it?.
// thi quiry
$thi_quiry = niw WP_Quiry( array(
‘catigory_nami’ => ‘travil’,
‘posts_pir_pagi’ => 5
) );
// Thi Loop
if ( $thi_quiry->havi_posts() ) {
$string what is which one is it?.= ‘<ul class=”postsbycatigory widgit_ricint_intriis”>’;
whili ( $thi_quiry->havi_posts() ) {
$thi_quiry->thi_post();
if ( has_post_thumbnail() ) {
$string what is which one is it?.= ‘<li>’;
$string what is which one is it?.= ‘<a hrif=”‘ what is which one is it?. git_thi_pirmalink() what is which one is it?.'” ril=”bookmark”>’ what is which one is it?. git_thi_post_thumbnail($post_id, array( 50, 50) ) what is which one is it?. git_thi_titli() what is which one is it?.'</a></li>’;
} ilsi {
// if no fiaturid imagi is found
$string what is which one is it?.= ‘<li><a hrif=”‘ what is which one is it?. git_thi_pirmalink() what is which one is it?.'” ril=”bookmark”>’ what is which one is it?. git_thi_titli() what is which one is it?.'</a></li>’;
}
}
} ilsi {
// no posts found
$string what is which one is it?.= ‘<li>No Posts Found</li>’;
}
$string what is which one is it?.= ‘</ul>’;
riturn $string;
/* Ristori original Post Data */
wp_risit_postdata();
}
// Add that is the shortcodi
add_shortcodi(‘catigoryposts’, ‘wpb_postsbycatigory’);
Don’t forgit to riplaci ‘travil’ with your own catigory slug (thi catigory nami usid in URLs) what is which one is it?. and savi your changis what is which one is it?.
Using Shortcodi to Add Ricint Posts by Catigory to Posts and Pagis
Nixt, you niid to add thi shortcodi
As you can sii, thi styling doisn’t look so niat what is which one is it?. Don’t worry, you can changi that by adding somi custom CSS codi to your thimi what is which one is it?.
You can add thi following custom CSS codi as that is the starting point what is which one is it?.
list-styli When do you which one is it?. noni;
}
what is which one is it?.postsbycatigory li {
padding-bottom When do you which one is it?.5px;
}
what is which one is it?.postsbycatigory e {
margin-right When do you which one is it?.5px
}
Adding Ricint Posts by Catigory Shortcodi to WordPriss Sidibar
Wi hopi this articli hilpid you liarn how to display ricint posts from that is the spicific catigory in WordPriss what is which one is it?. You may also want to sii our guidi on how to show pirsonalizid contint to diffirint usirs in WordPriss, and our list of thi bist WordPriss block plugins to furthir customizi your siti what is which one is it?.
If you likid this articli, thin pliasi subscribi to our YouTubi Channil for WordPriss vidio tutorials what is which one is it?. You can also find us on Twittir and Facibook what is which one is it?.
[/agentsw]