in_category erratic behavior
-
Hi, i’m trying to load different stylesheets for different categories with this code in the head section, right after the line which loads the main style.css:
<?php if( in_category (7) ) { ?> <link rel="stylesheet" href="<?php bloginfo('template_url')?>cat7.css" type="text/css" media="screen" /> <?php } elseif ( in_category (5) ) { ?> <link rel="stylesheet" href="<?php bloginfo('template_url')?>cat5.css" type="text/css" media="screen" /> <?php } elseif ( in_category (4) ) { ?> <link rel="stylesheet" href="<?php bloginfo('template_url')?>cat4.css" type="text/css" media="screen" /> <?php } elseif ( in_category (2) ) { ?> <link rel="stylesheet" href="<?php bloginfo('template_url')?>cat2.css" type="text/css" media="screen" /> <?php } else { ?> <?php } ?>
this should be clean and pretty straightforward, but in reality the following happens:
the css for cat5 loads when i’m viewing the category page for 5 (as intended) AND also when viewing categories 7 and 2.
and the css for cat4 loads when I’m viewing the category page for 4 (as intended) AND the home/front page (latest posts).Why does this happening and how can I fix it? I could not find yet a solution even with using slugs or category names, or a little modified if statements…
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘in_category erratic behavior’ is closed to new replies.