Childs child of parent category
-
I’m trying to create a conditional statement, for when a category is a sub-sub-category. So, not just 1 level deep, but 2 levels deep. So, I don’t just want to see if I am in a child category of a parent category, but a grandchild of that category.
For example… if my site was a list of professions, then I might have the following categories
1. Professions (main category – parent)
a) Home & Garden (subcategory – child)
i) Gardeners (sub-subcategory – grandchild)So, when the user is on the “Gardener’s” category page (or any sub-subcategory page), then I can show something (with the conditional statement).
I checked the codex, and that shows something for looking for something in as a “descendent” of a category… but that wont work for “two levels” deep (a “descendent’s descendent”).
// Post is assigned to "fruit" category or any descendant of "fruit" category? <?php if ( in_category( 'fruit' ) || post_is_in_descendant_category( 11 ) ) { // These are all fruits… } ?>
Can someone help? Thanks!
- The topic ‘Childs child of parent category’ is closed to new replies.