How To Display Recent Posts From Only A Specific Category In WordPress
By default, WordPress uses a ‘Recent Posts’ widget that lets you show your recent posts in your current WordPress theme. But what do you do when you want to show the most recent posts from only one particular category?
There are two ways to accomplish this: one is through the use of a plugin, and the other is by adding a few lines of code in the template file. I’ll be showing you two different tutorials that will teach you how to go about each.
The first method involves a bit of coding. All you have to do is add this code anywhere in the WordPress template files:
<?php $recent = new WP_Query("cat=5&showposts=8"); while($recent->have_posts()) : $recent->the_post(); ?>
<ul>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
</li>
</ul> <?php endwhile; ?>
This code will display eight recent posts from the category whose cat ID (or category ID) is ‘5’. If you want to display more (or less) than eight posts you can change the numeric value to your preferred number of posts. The category ID, of course, will depend on the actual ID of your category/ies. To find it, just go to your dashboard and head over to ‘Manage’. And then in ‘Categories’, simply hover your mouse over the ‘Edit’ link of the particular category you want to know the ID of and then look at your browser’s status bar. You should see something that looks like this:
http://www.yoursite.com/wp-admin/categories.php?action=edit&cat_ID=5
As you can see at the end, the cat ID in the above example is ‘5’.
Now for the second method, I decided to just let this video tutorial by Josh Galvan from Tizish show you how to display only your recent posts from a particular category with the use of a widget called ‘Category Posts Widget’.
Hope you find one of these methods helpful. Cheers!
Incoming search terms for the article:
- display recent posts from a specific category
- only show previous posts from a particular category
- 5 recent posts from category
- wordpress post specific category
- wordpress only show posts from specific category
- specific template for a category wordpress
- show recent posts in current category only
- show posts from specific category wordpress neatly
- show only particular category in blog
- recent posts from only a catagory