How to Display Recent Posts From A Specific Category In WordPress

Do you want to display recent posts from a specific category in WordPress? The default recent posts widget shows posts from all categories, and there is no option to filter them by category. In this article, we will show you how to easily display recent… Read More »

The post How to Display Recent Posts From A Specific Category In WordPress appeared first on WPBeginner.

Do you want to display recent posts from a specific category in WordPress? The default recent posts widget shows posts from all categories, and there is no option to filter them by category. In this article, we will show you how to easily display recent posts from a specific category in WordPress.

Display recent posts from specific category in WordPress

Filtering Posts by Category in WordPress

If you just want to create a page to display recent posts from a particular category, then your WordPress site already has separate pages for each category.

You can add links to all your category pages by visiting Appearance » Widgets page and adding the ‘Categories’ widget to your sidebar. You can also add categories in your navigation menus.

On the other hand, if you want to show recent posts from a specific category in your sidebar, then there is no default widget for that. The default recent posts widget does not allow you to filter posts by category or tags.

Thankfully there is another way. Let’s take a look at how to easily display recent posts from specific category in WordPress.

Method 1. Show Recent Posts from a Category Using Plugin

This method is easier, and it is recommended for most users.

First thing you need to do is install and activate the Recent Posts Widget Extended plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit the Appearance » Widgets page and add ‘Recent Posts Extended’ widget to your sidebar.

Limit recent posts by category

The widget menu will expand to show its settings. You need to select the category or categories that you want to display under the ‘Limit to Category’ option.

The widget comes with a lot of options that you can customize. You can show post thumbnail, date, relative date, post summary / excerpts, and more.

Don’t forget to click on the save button to store your widget settings.

You can now visit your website to see the recent posts displayed by category.

Recent posts from specific category

Display Recent Posts by Category Using Shortcode

The Recent Posts Extended Widget also allows you to use shortcode to display recent posts anywhere on your site including posts and pages.

You will need to edit the post or page where you want to display the recent posts from a specific category. In the post editor, you will need to add the following shortcode:

[rpwe limit="5" excerpt="true" cat="72" ]

This shortcode displays 5 recent posts from a specific category with the post excerpt. You will need to replace the cat value with the ID of the category that you want to display. See our article on how to find category ID in WordPress.

After adding the shortcode, you can save your post or page to view your changes.

Posts by category displayed using shortcode

Method 2. Display Recent Posts From Specific Category using Code Snippet

This method requires you to add code to your WordPress theme files. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

You will need to add the following code in your WordPress theme files where you want to display recent posts from a specific category.

<?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();
?>

The first line of this code creates a new WordPress query with a specific category ID. You need to replace it with your own category ID. It only shows post title in a list.

You can change it to display full content by adding the following code:

<?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(); ?>

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

We hope this article showed you how to easily display recent posts from a specific category in WordPress. You may also want to see our list of most wanted category hacks and plugins for WordPress.

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.

The post How to Display Recent Posts From A Specific Category In WordPress appeared first on WPBeginner.

How to Display Recent Posts From A Specific Category In WordPress

Do you want to display recent posts from a specific category in WordPress? The default recent posts widget shows posts from all categories, and there is no option to filter them by category. In this article, we will show you how to easily display recent… Read More »

The post How to Display Recent Posts From A Specific Category In WordPress appeared first on WPBeginner.

Do you want to display recent posts from a specific category in WordPress? The default recent posts widget shows posts from all categories, and there is no option to filter them by category. In this article, we will show you how to easily display recent posts from a specific category in WordPress.

Display recent posts from specific category in WordPress

Filtering Posts by Category in WordPress

If you just want to create a page to display recent posts from a particular category, then your WordPress site already has separate pages for each category.

You can add links to all your category pages by visiting Appearance » Widgets page and adding the ‘Categories’ widget to your sidebar. You can also add categories in your navigation menus.

On the other hand, if you want to show recent posts from a specific category in your sidebar, then there is no default widget for that. The default recent posts widget does not allow you to filter posts by category or tags.

Thankfully there is another way. Let’s take a look at how to easily display recent posts from specific category in WordPress.

Method 1. Show Recent Posts from a Category Using Plugin

This method is easier, and it is recommended for most users.

First thing you need to do is install and activate the Recent Posts Widget Extended plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit the Appearance » Widgets page and add ‘Recent Posts Extended’ widget to your sidebar.

Limit recent posts by category

The widget menu will expand to show its settings. You need to select the category or categories that you want to display under the ‘Limit to Category’ option.

The widget comes with a lot of options that you can customize. You can show post thumbnail, date, relative date, post summary / excerpts, and more.

Don’t forget to click on the save button to store your widget settings.

You can now visit your website to see the recent posts displayed by category.

Recent posts from specific category

Display Recent Posts by Category Using Shortcode

The Recent Posts Extended Widget also allows you to use shortcode to display recent posts anywhere on your site including posts and pages.

You will need to edit the post or page where you want to display the recent posts from a specific category. In the post editor, you will need to add the following shortcode:

[rpwe limit="5" excerpt="true" cat="72" ]

This shortcode displays 5 recent posts from a specific category with the post excerpt. You will need to replace the cat value with the ID of the category that you want to display. See our article on how to find category ID in WordPress.

After adding the shortcode, you can save your post or page to view your changes.

Posts by category displayed using shortcode

Method 2. Display Recent Posts From Specific Category using Code Snippet

This method requires you to add code to your WordPress theme files. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

You will need to add the following code in your WordPress theme files where you want to display recent posts from a specific category.

<?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();
?>

The first line of this code creates a new WordPress query with a specific category ID. You need to replace it with your own category ID. It only shows post title in a list.

You can change it to display full content by adding the following code:

<?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(); ?>

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

We hope this article showed you how to easily display recent posts from a specific category in WordPress. You may also want to see our list of most wanted category hacks and plugins for WordPress.

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.

The post How to Display Recent Posts From A Specific Category In WordPress appeared first on WPBeginner.

How to Display Recent Posts in WordPress

Displaying Recent posts often helps your users to visit them easily specially on the sidebar of a single post page. But in some designing processes people want to display recent posts in many different ways. In this post, we will show you various different ways you can display the recent posts in WordPress.

To leave a comment please visit How to Display Recent Posts in WordPress on WPBeginner.

Do you want to show your recent posts in WordPress? Displaying recent posts helps your users find them easily. You can add recent posts in your sidebar, after the end of your post content, inside your post content with a shortcode, in your footer widget areas, and basically anywhere else that you like. In this article, we will show you how to display recent posts in WordPress with a plugin, widget, shortcode, and the manual method with the recent post function.

A WordPress page with recent posts listed

Using The WordPress Recent Posts Widget

WordPress comes with a built-in default widget to display recent posts in your site’s sidebar or any widget ready area. Inside your WordPress admin, simply visit Appearance » Widgets and add Recent Posts widget to a sidebar.

Using the default WordPress recent posts widget

The built-in recent posts widget is very basic. You can provide an alternate title to the widget, show date, and add the number of posts you want to display. Next, click on the save button to store your widget settings.

Using Recent Posts Widget Extended Plugin

As you noticed that the built-in widget we mentioned above is quite limited, and it doesn’t even allow you to show thumbnails or excerpts which is often a priority for users.

What if you wanted to display thumbnails and excerpts with your recent posts? What if you wanted to limit them to specific categories or tags?

Well, that’s when Recent Posts Widget Extended plugin comes in handy.

First thing you need to do is install and activate the WordPress Recent Posts Widget Extended plugin. Upon activation, simply visit Appearance » Widgets and add Recent Posts Extended widget to a sidebar.

Recent posts extended widget settings

Recent Posts Extended widget comes with a lot options and gives you full control on how you want to display recent posts on your WordPress site. You can show thumbnails, excerpts, limit categories and tags, ignore sticky posts, and much more. You can even use the widget to display recent posts from any other post type on your site.

Recent posts with thumbnail and excerpt in  sidebar widget

Displaying Recent Posts in WordPress Using Shortcode

Adding recent posts to a sidebar is fairly easy, but what if you wanted to show recent posts inside a WordPress post or page? The easiest way to display recent posts in WordPress posts and pages is by using shortcodes.

First thing you need to do is install and activate the Display Posts Shortcode plugin. It works out of the box and there are no settings for you to configure.

Simply edit a post or page where you want to display your recent posts. Next, use the shortcode [display-posts] with your own parameters inside the post. The plugin offers a whole range of parameters that you can use with the shortcode. Here are some examples:

Display 5 recent posts with thumbnails and excerpt

[display-posts posts_per_page="5" image_size="thumbnail" include_excerpt="true"]

Display recent pages instead of posts

[display-posts posts_per_page="5" post_type="page"]

Change the order to title instead of date.

[display-posts posts_per_page="5" orderby="title"]

Display recent pages under a specific parent page.

[display-posts posts_per_page="5" post_type="page" post_parent="5"]

For a full list of parameters visit the plugin’s documentation.

You can also use these shortcodes inside a text widget, but first you will need to enable shortcodes in your text widgets by adding this code to your theme’s functions.php file or a site specific plugin.

add_filter('widget_text', 'do_shortcode');

Displaying Recent Posts Manually in WordPress Theme Files

More advanced WordPress users may want to add recent posts directly in their WordPress theme files. There are multiple ways to do this, but the easiest one is to use the built-in WP_Query class. Simply add this code where you want to display the recent posts.

<ul>
// Define our WP Query Parameters
<?php $the_query = new WP_Query( 'posts_per_page=5' ); ?>

// Start our WP Query
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

// Display the Post Title with Hyperlink
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>

// Display the Post Excerpt
<li><?php the_excerpt(__('(more…)')); ?></li>

// Repeat the process and reset once it hits the limit
<?php 
endwhile;
wp_reset_postdata();
?>
</ul>

This code simply displays five most recent posts with their title and excerpt. The WP_Query class has tons of parameters that allows you to customize it any way that you like. For more information please refer to the codex.

We hope that this article helped you learn how to display recent posts in WordPress. If you want to customize the display of your recent posts without writing any code, then you may want to check out CSS Hero, a WordPress plugin that helps make design customization easy – see our full CSS Hero review.

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.

To leave a comment please visit How to Display Recent Posts in WordPress on WPBeginner.