Tag: conditional

Show Only Category (Not Subcategory) Content

If you ever wanted to only show the content of the category you were on in the category view of WordPress (instead of the category you are on plus all of it’s subcategories – you can easily do so by adding the code below to the template that is used to show your category content

You would start your loop with this:

 

Put your title, content functions here

and where you normally see the call, put to close the additional (in_category) if statement.

This code gets the current category and then only displays categories that are in that category (not sub category)

Exclude Single Category in WordPress

If you ever need to exclude a single category from a WordPress page (archives, index, category page, etc) you can easily do so by using a little conditional tag code within the WordPress loop.

The example below will skip over any post that is in the category with the ID of 35:





This can be helpful if you want to not show a particular category in your blog (if you have a category based site setup) – or if you want to hide some categories from your search results.