If you are a WordPress developer there is a good chance that you might be looking for a way to display recent posts from a special category either in the homepage or in a custom designed landing page. Well, we have provided a simple guide for you.
By following the tutorial given here, you will be able to display recent posts from a particular category in WordPress.
How To Display Recent Posts By Category In WordPress
1) To get started, log into your WordPress dashboard. Once done, click “Editor” under the “Appearance” tab.
2) Now, paste the following .php code either in “homepage.php” or “front-page.php” or “footer.php” or in any other place where you want to display recent posts from a specific category.
$catquery = new WP_Query( 'cat=2&posts_per_page=5' );
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>
<?php endwhile; ?>
By adding this code, you can display recent posts from a particular category in WordPress. To change the category, change the number next to “cat=” (the number is the category ID, which you can find from here: Posts -> Categories).
Also, you can change the number of recent posts display by changing the number next to “posts_per_page=” in the code given above.
If you are designing a magazine styled WordPress theme or if you are customizing your WordPress blog to give a magazine styled look, this tutorial will be of immense help to you.
If you encounter any issues while following this tutorial, do let me know via comments.