Forums

changing css for each page or subpage (6 posts)

  1. reprocessor
    Member
    Posted 2 years ago #

    Hi all,

    Need a little help with some php/css, I'm quite new to wordpress and I'm not sure how to do this. Here's what I want to do:

    I have set up pages (and sub-pages thereof) for different sections of the website e.g. about, products, services, contacts etc. (Sorry I can't show anyone coz i'm running it off XAMPP) Each section needs to be a different colour therefore will require a separate stylesheet (I need to do it this way as I may need to add subtract colours). Is there a php call that you can stick in the header that will, say, if the page name (or parent) is 'about' then it'll use stylesheet 'x-green.css' or if the page name (or parent) is 'products' it'll use 'x-orange.css'? I've got 6 colours in all to go thru :(

    Any help here would be greatly appreciated.

    Thanks in advance for anyone willing to help me with this.

    Phil

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    After this line in your theme's header.php:

    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

    put something like this:

    <?php
    if ( is_page('about')) { ?>
    <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/style-about.css" />
    <?php } ?>
    
    <?php
    if ( is_page('products')) { ?>
    <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/style-products.css" />
    <?php } ?>
    
    <?php
    if ( is_page('services')) { ?>
    <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/style-services.css" />
    <?php } ?>
    
    <?php
    if ( is_page('contacts')) { ?>
    <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/style-contacts.css" />
    <?php } ?>
    ?>

    Above extracted from:
    http://wordpress.org/support/topic/236049
    http://wordpress.org/support/topic/218597

  3. reprocessor
    Member
    Posted 2 years ago #

    That is absolutely brilliant!!! Thanks dude :)

    Do you know how to get it to work on 'child' pages?
    Just say in the 'about' section there's 'latest news', 'jobs' & 'contact' where 'about' is their parent
    how would I go about adding the code

    <?php
    if ( is_page('about')WOULD IT BE IN HERE - IF SO HOW DO U DO IT?) { ?>
    <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/style-about.css" />
    <?php } ?>

    or would it be something like:

    if ( is_page+child('about')

    i'm not sure so any help would be amazing :)

    Phil

  4. MichaelH
    Volunteer
    Posted 2 years ago #

    if ( is_page(array('about','child1ofabout','child2ofabout')))

  5. reprocessor
    Member
    Posted 2 years ago #

    Hi Michael,

    Sorry to be a pain but your last solution didn't work. Any other ideas?

    I really appreciate your help by the way ;)

    Phil

  6. MichaelH
    Volunteer
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags