web
analytics
≡ Menu

Display Recent Post From a Specific Category in WordPress

In some cases you may want to display recent posts in your blog from specific categories. For example if you have a category with a name “Technology” then copy the following code and past in your function.php file. If you are using thesis theme, then make sure to add thesis_hook call for the placement of the recent posts.

and

If you are using any other wordpress theme, then go to the Appearance>Editor and single.php file and place the code.

<?php
query_posts(’showposts=1&cat=3′);
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h3>
<ul><li><?php the_content(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>

Make sure to change the values in Showposts=1 and Cat=3.

Where showposts = The number of post to be displayed

and

Cat= 3 is the ID of the Category.

You can find the ID of a specific category from your Dash Board – Post – Category. Place the mouse on a category, and you will see ID for that Category. Just look at to the below screen shot.display recent post You can see in the screen shot that ID for Adsense Category is 12. Similarly you can also find ID for other categories.

Change the ID and save the file.

That’s it.

{ 2 comments… add one }
  • Blogsolute

    November 11, 2009, 1:46 pm

    Yep, If coding seems difficult to any of the users, there is a plugin called “Related Posts by Category” which show posts from specific category and moreover, it detects the category of article and shows from the same, unlike mentioning category ID as stated here.

    Reply
  • Chand

    November 11, 2009, 1:58 pm

    Well if a single and simple code can do this, then why overloading your blog with allot of Plugins.
    It is better to try CSS not Plugins.
    Thanks for your comment.

    Reply

Leave a Comment