Dan Davies{ Front-end Developer }

Hide and show WordPress post categories

3rd December 2011

Of late, I’ve been doing this more than anything else in WordPress. It took me a while to figure it out as there seems to be various ways of doing it or it certainly looks that way. Some complicated and some long winded.

But finally I have something that allows me to hide and show what ever category I want and where.

For example, this site. My blog posts are in their own category. Also, my portfolio pieces are blog posts too but have their own category. I don’t want my portfolio posts to appear in either my blog or the archives so I need to hide them.

So simply, I added this just outside the loop.

?php query_posts ('cat=-4'); ?>

Basically, its saying don’t show category 4 which is of course my portfolio posts.

Another option is to use

?php query_posts ('cat=3'); ?>

That is saying only show category 3 which is my blog posts category

Simple eh?

Is there a better way that you know of? Let me know.

Back to top