Under your dashboard, go to Manage —> Categories —> and you’ll see a list of all your cats in this type of format:
— parent cat
— — child cat
— — child cat
— — child cat
— parent cat
— — child cat
On the far left, right before the name of each category, is the ID number, which is what you put between the ( ) in the conditional statement. If you create a conditional statement for any parent cat, all the child cats under it will also be included unless you specifically designate otherwise.
Awesome. I’ve already got the conditionals worked out for all the top level cats. Then it appears my setup will work fine just as it is.
Thanks for the reply 🙂
“If you create a conditional statement for any parent cat, all the child cats under it will also be included unless you specifically designate otherwise.“
That is not correct. is_category() only evaluates the current category. With that conditional you’d need to use an if statement like:
if( is_category(Parent) || is_category(Child1) || is_category(Child2) || is_category(Child3) || etc… )
I wrote up code a while back that provides a conditional that returns true for a category ID *or* its child categories. Let me know if you could use that and I’ll wrap it in a plugin.
Kafkaesqui: I could use that as a plugin!
Well that’s one yes vote!
is_category_parent() plugin:
download plugin | view source
Download the file and upload it to your plugins directory, then activate is_category_parent() under Plugins. Use it like you would the is_category() conditional:
<?php if(is_category_parent(10)) : ?>
~ Displays if current or parent category is 10 ~
<?php endif; ?>
Notes: is_category_parent() only accepts a numeric category ID; to accept category names would require querying the database to match against them, which I felt was overkill. It also only affirms ‘direct’ child or sub- categories. It could be rewritten to work down through any level of category nesting, but again we’re talking about queries to the database…
Awesome, I’m probably going to give this a go. Will this work in the post pages as well? My conditionals I found out only work while viewing category listings.
liquilife, is_category() only works on category queries, so this only works then, as well. I don’t know if it will help, but you can take a look at two plugins I’ve written that deal with matching category template to post, and in the latter case child category to parent category template:
http://guff.szub.net/2005/07/21/post-templates-by-category/
http://wordpress.org/support/topic/58382#post-315039
It seems that parent categories have category_parent = 0 in the database, so you could use this to filter only parent categories:
<?php if(is_category_parent('0')) : ?>
~ Displays only if current is a parent category ~
<?php endif; ?>
This way we can use a template to parent and another one to children categories.