find wordpress posts by category name

How to display recent posts from category

In custom themes, we choose category to show the posts from which will be a good trick. In this article we given code for display recent posts from category.

How to display recent posts from category

Use following code for showing the recent post from category:


<?php
query_posts('showposts=1&cat= get_cat_id('category_name')');
while(have_posts()) : the_post();
?>
<h3>php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></h3>
<pre>
<?php the_content(); ?>
<?php endwhile; ?>

You can replace the category_name to your category name

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “How to display recent posts from category”

  1. This doesn't seem to be working in the latest version of wordpress. It was giving me a blank page until I removed the quotes around the category name, and then it was simply returning every post instead of just that category. Anyone know who to make this work?

Leave a Reply to Nicole Cancel reply

Your email address will not be published.