How To Display the Recent Posts of Specific Categories Wordpress
or How to Exclude Specific Categories and Display any Number of Posts”
Wordpress has many functions to user with many ways, today i will give you many option to play with categories post, you can use these codes any place, even on your home page (yourtemplate/index.php) or sidebars (yourtemplate/sitebar.php).
Im sure this is very easy way to edit wordpress function or class for your requirements.
Exclude/avoid Specific Category PostÂ
for exclude or avoid any specific category post on home (yourtemplate/index.php) you need to use these codes.
<?php query_posts(’cat=-1′);?> # category ‘1′ post will be excluded by this codes, you can replace ‘1′ as per your category id.
 Exclude/avoid multiple categories
<?php query_posts(’cat=-1,-2,-3,-4′);?> # category ‘1′,’2′, ‘3′, ‘4′Â post will be excluded by this codes, you can replace ‘1′,’2′, ‘3′, ‘4′ as per your category id.
Display Specific Category PostÂ
<?php query_posts(’cat=1′);?> # category ‘1′ post will be excluded by this codes, you can replace ‘1′ as per your category id.
Dispaly Specific multiple categories Post
<?php query_posts(’cat=1,2,3,4′);?> # category ‘1′,’2′, ‘3′, ‘4′Â post display
Display some fixed number of posts
<?php query_posts(’showposts=1′);?> ## only 1 recent post will be display.
Display some fixed number of posts + Specific Category
<?php query_posts(’cat=1&showposts=6′);?> ## only 1 recent post will be display.
Where/How to use these functions in your pages
Let start to display on home page as we have done on www.w3cgallery.com home page under ”recent blog posts”.
We have  6 recent post with Specific Category, mean <?php query_posts(’cat=1&showposts=6′);?>Â
codes on home page (yourtemplate/index.php)
Line 10/11.
 <?php
 if (have_posts()) : ?>
 Â
   <?php
 Â
  while (have_posts()) : the_post();
 Â
  ?> ……. etc.add function like this
 <?php
 if (have_posts()) : ?>
Â
 <?php query_posts(’cat=2&showposts=6′);?>  <?php
 Â
  while (have_posts()) : the_post();
 Â
  ?>
I guess it will help you guys..













July 29th, 2010 at 12:50 am
Try it