0

I have a category structure for comics. There is a parent category called Comics (id 6 in my case) and each comic series is a child of it.

So I want to introduce in my theme a function to check whether something is a comic or not, with the idea that I could either call it empty to check whether the current page or element in the loop is of a comic, or I could give it a category to see if it's of a comic.

My code so far is this

function is_comic($categories=get_the_category()){
  foreach ($categories as $cat) {
    if ( (is_int($cat) and $cat==6) or ($cat->term_id == 6) or ( cat_is_ancestor_of(6,$cat) ) ){
      return true;
    }
  }
  return false;
}

But it just crashes my site. EDIT: Found a missing parenthesis, but assigning the default value still crashes the site. How would you assign the default so it gets the categories of the current page?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.