Excluding Multiple Categories In WordPress

Whilst working on a clients site today, adding a new section, I came across a small problem where I needed to exclude 2 categories from the themes index.php file.

The home page only contains one post, so to make sure no one could fiddle with the amount of posts shown I hard coded in a limit by adding this:

<?php query_posts('showposts=1'); ?>

Having that code in there meant I could simple add a few characters to exclude categories. Adding &cat=-71 worked fine, but when it came to excluding the second category, I wasn’t sure what to do. I know there are numerous plugins for this, but I don’t want to give the client the ability so screw things up so I needed to hard-code it in.

The solution was quite simple: Just add a comma followed by a minus(-) and then the category ID. Sorted.

<?php query_posts('showposts=1&cat=-71,-72'); ?>