How To Guide To Show Recent Posts by Category in WordPress
In today’s how-to blog post, you’ll learn how to show recent posts by category in WordPress. If you want to showcase a specific category in WordPress sidebar widget, you can choose one of two methods. First one is an easy method, and it’s by using a plugin called category posts widget. To get started we’ll just install and activate the plugin then go to appearance, widget and drag the category post widget where you want it to go.
From there you can give it a title, choose which category you want to show, and the number of posts to show for the category you can also choose how to sort it. You have all these other options down here to choose from. Just customize it to fit your needs and when you’re finished, click save. Now we can go to our demo site and see it in action. Here, it’s showing the last 5 from my category like I want it to. The second way to do this is a little bit more advanced it does not require a plugin, but it does require you to add some code to your theme’s function.php file.
First, you want to make sure you backup your site. And then you add the code like this to your functions.php file. When choosing your category slug make sure you put your category in there. This code brings back the 10 posts from a specific category and displays in a bulleted list.
If the post has a featured image, then it will show that as well. Now we can add this code to show our list on either a footer or a single.php file. Or you can just add the text widget under appearance, widgets and add the shortcode here. You can see what it looks like on the demo site. You’ll also need to add some CSS to make the list look better so test different CSS codes to tweak it to your liking. As found on Youtube
If you enjoyed this blog post be sure to click on the share button below and leave us a comment.
And if you want to receive more helpful post don’t forget to subscribe to our feed and check out https://shaneperry.co/blog for more useful information on websites.