Support » Themes and Templates » Different Stylesheets for Different Categories?

  • Hi is it possible to call different stylesheets for different categories?

    So if I was in cat 5 it would display style1.css
    and if I was in cat 7 it would display style2.css

    Is this possible without the use of a plugin, and I want it so that server work is minimal.

Viewing 1 replies (of 1 total)
  • You can do it in the header.php file (of most themes). This requires running the loop though (as in_category is normally run inside it). It might cause a bit of overhead in your theme.

    Like so:

    <?php if (have_posts()) { the_post(); rewind_posts(); } ?>
    <?php if (in_category(5)) { ?>
      <link rel="stylesheet" href="style/style1.css" type="text/css" media="screen" />
    <?php } else if (in_category(7)) { ?>
      <link rel="stylesheet" href="style/style2.css" type="text/css" media="screen" />
    <?php } ?>

    And so on. I haven’t tested that, but it should work.

Viewing 1 replies (of 1 total)
  • The topic ‘Different Stylesheets for Different Categories?’ is closed to new replies.