Quantcast

May 23, 2012

How to Exclude a Blog Category from Displaying

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]

About Rosalind Gardner

Rosalind Gardner is a blogger, speaker and Internet Marketing consultant, best known for her "Super Affiliate Handbook", (referred to by industry professionals as the 'bible' of affiliate marketing) and Rosalind Gardner's Academy - a multi-media version of the book.

Comments

  1. Michael Chalke says:

    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.

Disclosure: We are compensated for our reviews. Click here for details.