Home / Softwares/Apps / Two Methods to Display Recent Posts From A Specific Category In WordPress

Two Methods to Display Recent Posts From A Specific Category In WordPress

WordPressAre you looking forward to show recent posts from a desired category in WordPress? The default posts widget will display posts from all categories. So you have no option to filter these by category of your choice.

Here, you will learn how to display recent posts from a desired category in WordPress:

In case, you simply want to create a page for displaying recent posts from a specific category, then don’t worry. WordPress website comes with distinct pages for each category.

Game of the Week: Subway Surf Run App Store Link

So you can easily add links to all of your category pages. For this, simply visit an Appearance » Widgets page. Thereafter, add ‘Categories’ widget to your sidebar. Categories can also be added to your navigation menus.

Game of the Week: Subway Surf Run App Store Link

However, there is no default widget for displaying recent posts from a specific category in your sidebar. Luckily, there is an alternative.

Here are two methods you can follow for the same:

Method One

This is an easier method and recommended by experts. Jitesh Manaktala is a freelance web designer & WordPress front-end developer who recommends methods for most users. Here’s what you need to do:

Step 1: Install and activate the Recent Posts Widget Extended plugin.

Step 2: Once the activation is done successfully, visit the Appearance » Widgets page.

Step 3: Add ‘Recent Posts Extended’ widget to your sidebar.

Step 4: Now widget menu will expand to display its settings. Choose the category (s)
you wish to show under the option ‘Limit to Category’.

Step 5: This widget is available with several options that you may easily customize. For instance, you can display relative date, post thumbnail, excerpts, date, post summary and much more.s

Step 6: Store your widget settings by clicking on the save button.

Step 7: Now you can visit your website to view recent posts displayed by category.

The Recent Posts Extended Widget will also let you use the shortcode for showing recent posts anywhere on your website including pages and posts.

You must edit the page or post where you wish to show recent posts from a desired category. Add the shortcode stated below in the post editor:

[rpwe limit=”5″ excerpt=”true” cat=”72″ ]

The shortcode shows around five recent posts from a particular category with the post excerpt. Replace the cat value with the ID of the category you wish to display. Once you add the shortcode, it is time to save your page or post to view changes.

Method Two

Here, you need to add code to your WordPress theme files. Not used to try this out before? Simply look for online guides about copying and pasting code in WordPress.

Add the following code in your WordPress theme files. This should be added right where you wish to display recent posts from a particular category.

1
2
3
4
5
6
7
8
9

<?php $catquery = new WP_Query( ‘cat=72&posts_per_page=5’ ); ?>
<ul>
<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<li><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></li>
<?php endwhile;
wp_reset_postdata();
?>

A new query for WordPress is created by first line of this code. This is created with a specific category ID. Replace this ID with your own category ID. You will see only post title in a list.

Change it to show the full content. You can do this via adding the code given below:

1
2
3
4
5
6
7
8
9
10

<?php $catquery = new WP_Query( ‘cat=72&posts_per_page=5’ ); ?>
<ul>
<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<li><h3><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h3>
<ul><li><?php the_content(); ?></li>
</ul>
</li>
<?php endwhile; ?>
</ul>
<?php wp_reset_postdata(); ?>

This can also replace the the_content with the_excerpt to display post excerpts instead of the full article.

Hope this article helped you learn two easy methods on how to easily display recent posts from a specific category in WordPress that you desire.

Game of the Week: Subway Surf Run App Store Link

About vickyrathore

Check Also

Beautiful Skin

5 Best Plastic Surgery Apps

Plastic surgery is more affordable, less risky, and better at producing great results than ever …