• Resolved hb81

    (@hb81)


    I’m creating a theme which requires separate css documents for each section of the site so I have added this to the header.php

    <?php if ( is_page (98 )) : ?>
    <link rel=”stylesheet” type=”text/css” href=”<?php bloginfo(‘template_directory’); ?>/pilates.css” />
    <?php endif; ?>

    I’m a bit clueless with php – how can I add in a list of different pages that I want to apply this css to so I don’t have to do a separate one for each page, or better still say be able say ‘this page and all child pages’?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Justin

    (@jgwpk)

    Maybe

    <?php if ( is_page ( array(98, 34, 35, 36) ) ) : ?>
    <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/pilates.css" />
    <?php endif; ?>
    Thread Starter hb81

    (@hb81)

    Thanks! That works great, although it would be even better to have have a solution that meant that if my client adds a page to a section it would still apply the css without me having to go in and add the extra page id, if that’s possible?

    What you are after is already done for you by WP.

    Just review page section of body_class()
    http://codex.wordpress.org/Function_Reference/body_class

    For example, you can style a parent page with page id = 98 AND all its children pages with this.

    .page-id-98,
    .parent-pageid-98 {
    	color:red;
    	background:blue;
    }
    Thread Starter hb81

    (@hb81)

    Thanks, that’s a great solution that means I can ditch all those extra style sheets and not clutter up the page.php. Thanks for taking the time to respond.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Linking different CSS docs to groups of pages’ is closed to new replies.