• I am building a site where i need it to be sensitive to one category and load a special CSS just for that section. The CSS should over right the main CSS. Any info on this would be a wonderful help

    thanks! Rob

Viewing 4 replies - 1 through 4 (of 4 total)
  • On my site I add the categories to the post div classes:

    <div class="post<?php
        // add classes for categories
        foreach ((get_the_category()) as $category) {
            echo ' ' . $category->category_nicename;
        }
        ?>" id="post-<?php the_ID(); ?>">

    category-nicename gives the category slugs, so by default a ‘review pages’ category would be ‘review-pages’, for example.

    Say you have a category called ‘reviews’, make sure .reviews { } is below everything else in the CSS, so it overrides the settings above.

    This won’t replace the CSS of standard posts, but you can reset it all, e.g. if posts have margin: 1em then do margin: 0 to get rid of it in .reviews.

    If you have a separate CSS file, you could use @import at the bottom of style.css to add it on. If you don’t want to add the category classes to the separate CSS file, you could use some PHP to do the @import only on the pages with that category.

    Nice one Steve, cool.

    ??

    Cool, indeed. Flippin’ huzzah, is what I say.

    I’ve been using AsideShop for some time now and have recently begun to wish I could do more with it. It was a blessing but it also tended to get in the way in certain situations. As much functionality as it gave, it also could take some away.

    This solution works great so far. Thanks for the PHP skillz.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘CSS and catagories’ is closed to new replies.