Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using this function on functions.php and the goal is to call a specific template for any post inside a main category but this isn't working when I need to call a generic template for any other categories...

Help, please!

This is my code inside single.php:

<?php get_header(); ?>
<?php if ( in_category( 'cat1' ) || post_is_in_descendant_category( 3 ) ) {?>
<?php get_template_part('single-cat-1');?>

<?php } if ( in_category( 'cat2' ) || post_is_in_descendant_category( 1102 ) ) {?>
<?php get_template_part('single-cat-2');?>

<?php } if ( in_category( 'cat3' ) || post_is_in_descendant_category( 81 ) ) {?>
<?php get_template_part('single-cat-3');?>

<?php } else if (array(post__not_in(1102,81,3))) { ?>
<?php get_template_part('single-generic');?>
<?php }?>
share|improve this question
add comment

1 Answer

Think the code should be: (so far is working fine for me. Maybe it can be useful to someone...)

<?php get_header(); ?>
<?php if ( in_category( 'cat1') || post_is_in_descendant_category( 3 )) {?>
<?php get_template_part('single-cat1');?>
<?php } elseif (in_category('cat2') || post_is_in_descendant_category( 1102 ))  {?>
    <?php get_template_part('single-cat2');?>
<?php } elseif ( in_category( 'cat3' ) || post_is_in_descendant_category( 81 ))  {?>
    <?php get_template_part('single-cat3');?>
<?php } else {?>
    <?php get_template_part('single-generic');?>
<?php }?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.