How To Display the Recent Posts of Specific Categories Wordpress


2 Votes, Rating: 51 Star2 Stars3 Stars4 Stars5 Stars

Tags:

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..

Share/Save/Bookmark

One Response to “How To Display the Recent Posts of Specific Categories Wordpress”

  1. andreidelarosa@ says:

    Try it

Leave a Reply