How to Exclude a Blog Category from Displaying

Written by Rosalind Gardner  

Have you ever wanted to exclude a particular category from a section of your blog without using a plugin?

For example, because there is already a separate list of videos on the homepage at RosalindGardner.com, I didn’t want the videos to show up again in the “Most recent entry posted” featured at the top of the page.

So, to eliminate the Videos category from that section, I first look go to Manage > Categories in my Wordpress Administration panel and look for the category ID, which turns out to be #10.

I open the home.php template (you might be using index.php) and add cat=-10 to the code for the most recent post as follows:

< ?php $recent = new WP_Query("showposts=1&cat=-10"); while($recent->have_posts()) : $recent->the_post();?>

Note the minus sign in front of the category number.

If you want to eliminate more than one category from the display, simply separate each category ID number with a comma, such as: &cat=-10,-22 .

[tags]blog, wordpress, category, exclusions[/tags]


Related Posts

  1. Is Your Blog Featured On Facebook?
  2. Wordpress 2.5 Officially Released
  3. What’s the Point to Technorati Tags?
  4. Video Newsletter: March 11th, 2008
  5. How Do I Connect My Site and My Blog?

Comments

One Response to “How to Exclude a Blog Category from Displaying”
  1. Dear Rosalind, First I hope yopu are on the mend and getting over your traumatic surgery. Good Luck.xxx
    Second is that I have liked all the good things coming my way from you, but am surprised to see and unfortunately buy (£39.99) the programme on your blogsite.
    Namely “How I earn £14,246 a week”. This is a con for hard up pensioners like me. It’s a Gambling programme primarily, and betting against a Roulette Wheel and Football results. A Game of chance which I am sure will loose a lot of money if you followed it. I think he is also reselling with no Rights. I have asked for a refund.
    Thought you might like to know and perhaps check him out.
    Regards Michael Chalke.