• I have 6 category.php templates they all call header.php and so on and display the content, but they all look the same. So I create 6 styles sheets, the main one is called style.css and this is the default and required one for the header.php.

    How do I call a different style sheet in header.php? I don’t understand the if statements, so could someone explain this? I couldn’t find it in the codex (It only explains the content not styling via css for each template).

    Additionally, header.php has the main menu – makes sense since the header is called first (I think). Now within the header I have the current and active id tags for the css, which highlight the current template. What I want to do is call say category2.php to be the highlighted selection in the menu, but I can’t do this with one header.php can I?

    Please advise, thanks in advance

    EDIT: Just read this thread, it seems to heading in the right direction. Thing is copied index.php and only the header contains the CSS call, so I still need to figure out what to enter and where.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jinsan

    (@jinsan)

    The time to edit your post shoudl be longer, saves me having to bump the post (sorry to everyone else)

    Heres’ what I’ve come up with from reading al the current posts:
    <?if (is_category(1)) {
    echo "@import url( "/category-1.css");"
    } elseif (is_category(2)
    echo "@import url( "/category-2.css");"
    } elseif (is_category(3)
    echo "@import url( "/category-3.css");"
    } elseif (is_category(4)
    echo "@import url( "/category-4.css");"
    } elseif (is_category(5)
    echo "@import url( "/category-5.css");"
    } elseif (is_category(5)
    echo "@import url( "/category-5.css");"
    } else {
    echo "@import url( <?php bloginfo('stylesheet_url'); ?> );">?>

    I also need to account for a different css for seperate sections which are not categories such as about.php and contact.php how do I add those in the above and is it even correct?

    By all means use fancy php to select the correct sheet. But I wouldnt want people to get the idea that separate style sheets are really necessary at. With a bit of creativity and proper use of cascades and inheritance it could all go in one.

    Thread Starter jinsan

    (@jinsan)

    Ok just to update this is the procedure I took to get this to work:

    1) duplicate my index.php files for the number of categories I want to have
    2) duplicate my css for the number of categories I want to have
    3) duplicate header.php for the number of categories I want to have.

    Next steps:

    1) rename your index.php files to category-x.php where x = the category id which can be found in manage> categories. I don’t know if the hyphen is required, but I used it. so if you have a category called goats and it’s id is 17, rename your index.php to category-17.php

    2) rename your style.css files to category-x.css where x is the number of the category you wish to use for that stylesheet. I recommened you change the background colour in each style sheet to help distinguish if it’s working – just temporarily.

    3) rename your header.php files to header-x.php where is the number of the category you wish to use the header for.

    Next steps:

    1) take your new category-x.php files and open each one up one by one and find this:

    <?php get_header(); ?>

    replace this with:

    <?php load_template( TEMPLATEPATH . '/header-x.php'); ?>

    where x is the matching headerx.php file you have named. So if your category.php file is category-1.php then add header-1.php in the category-1.php file as above. repeat the procedure for your other files until your categories having matching headerphp files.

    2) open your header-x.php and find this:

    @import url( <?php bloginfo('stylesheet_url'); ?> );

    replace this with:

    @import url( http://yourdomain.com/wp-content/themes/yourtheme/category-x.css );

    where category-x.css is your style sheet for category-x.php. So if your style sheet is for category-3.php then the style sheet name would be category-3.php and so replace the category-x.css above with category-3.css.

    Now view your categories and you shoudl find the backgrounds (if you did what I said at the start) will change and you have now successfully customised your categories with a different style sheet. Customise the style as you want for each category and you should see the changes reflected.

    The use of seperate headers allow you to change the header image individually. As well as the style of menu, because you call a different CSS each time. So for one category you can have a vertical menu for another you can have a horizontal menu.

    If you have div id="masthead"> for your header image, for example, you can change the path of the masthead in the stylesheet for your any category by changing the path of the image in the css from background: url('images/masthead.jpg'); to background: url('images/category-x.jpg.); where category-x.jpg is the name of your masthead image for that category (you can call the jpg file anything you want).

    Now, what I want to do is keep the style for each category when a post is clicked, as right now it defaults to the default css and template. I assume that I just create new archives.php files for each category, and then repeat the above procedures to call each header for each category and that should keep the style for each category seperate, even when you click it.

    Hope this helps someone, and I hope someone can help me figure out the last bit (click on a post to get the styleto remain the same, I have no archives.php file for this theme!).

    Thanks in advance

    Root if you know a better way then please explain, I don’t know anything I’m working as is, so please share as it’s not the most useful comment. Thanks

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Calling different CSS in header.php’ is closed to new replies.