Excluding Categories / Tags from Specific Archives

December 11, 2011

If you’ve got a massive site like Bloginity, that features over 37 categories in total then you know you want to seperate these categories and make sure they are all laid out in a good way.

That’s why I created completely different archive pages for:

  • Author templates
  • Category templates
  • Tag templates

LIVE EXAMPLE OF CATEGORY/TAG TEMPLATES

  1. New York Fashion Week (TAG)
  2. Paris Fashion Week (TAG)
  3. Milan Fashion Week (TAG)
  4. London Fashion Week (TAG)
  5. Fashion Week (TAG)
  6. Fashion (CATEGORY)
  7. Arts (CATEGORY)

It’s so easy to achieve, head over to WordPress Codex and read up on the category/tag template and if you’re running into trouble then you’re obviously not doing it right. But if you are, and you were able to create a template for a tag, category then here’s the code on how to exclude certain categories and or tags from that category itself.

How to exclude a category from an archive template

Example: You have a category that’s name is “Food” and it’s ID is 3298 (use “Reveal IDs” plugin for WordPress to find the category ID).

Simply minus it, from where the cat= begins.

Throw this code in the template code and it should do the job just right.

query_posts($query_string . '&cat=-3298');

NOTE: You have to wrap it in a proper ?php open/close.

Leave a Comment

Previous post:

Next post: