I have function that check what is main top category of post. So i have category tree like this
Foo
-bar
--foobar
cat2
and if post is in foobar, my function post_is_in_descendant_category shows me “foo” and i can style that post with style-foo.css. What i want now is to make this same possible for styling category page “foobar”. WordPress functions in_category works only for posts.
So, my code if ( in_category( 'foo' ) || post_is_in_descendant_category( get_term_by( 'name', 'foo', 'category' )) || is_category('56') )
doesn’t work for subcategories.
If i understand right your “post_is_in_descendant_category” function checks if a post is descendant of a category and you want to check if a category is descentand. If so the add this function to your functions.php
and use it like this:
Hope this helps.
Try this: