• I’m making a WordPress website where lots of pages vary in colourscheme, but not layout. Is there an easy way of getting a certain page to select a stylesheet without using page templates or conditional tags? I kind of want it to be future-proof, so that as subpages are added, they continue to use the same template as the page parent.

    Perhaps some sort of global variable, whereby I have the variable store the page slug, and then use the variable to select the directory for the stylesheet.

    Kind of like

    <?php include($slug . "/style.css"); ?>

    Any thoughts on this would be appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Darfuria

    (@darfuria)

    Funbump!

    Maybe using something like

    <?php if($style = $slug . "_style.css") { include($style); } else { include("style.css") } ?>

    I haven’t looked into the specifics of this code, just a random idea I just got as I’m looking for the same solution and was intrigued by your suggested solution ?? Let me know if you figure it out!

    PW

    The simplest way to do it would be to use page templates.
    But, there’s no inheriting this, you need to create X number of template files, and every page you create you will have to tell, what template to use.

    Thread Starter Darfuria

    (@darfuria)

    I’d rather have a complicated way of doing this, as I’m working on the website for a family member and don’t really have to be stuck with endless administration.

    I hadn’t actually checked for any replies to this thread for a whie, so I’ll give that idea you suggested a go, Paul, and post the results. I’m sure there is a way of doing this.

    I’m looking to achieve a similar function.

    I’ve tried using conditional tags and seeing if a certain page will take a different css file but only messed up the whole layout on the pages.

    Any suggestions would be much appreciated.

    @ Zoomrix – how did you implement it?

    There are a few different approaches you could take the easiest being a conditional in header.php

    Let’s assume the page you want styled differently has the numerical ID of 123. Create a new style sheet for that page – for the sake of simplicity call it pg-123.css – and upload it to your theme’s folder.

    Next, open header.php and look for the call to your theme’s style sheet. It will look something like …

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

    … and wrap a few lines of code around it so it looks like this,

    <?php if ( is_page('123') ) { ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/pg-123.css" type="text/css" media="screen" />
    <?php } else { ?>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"  type="text/css" media="screen" />
    <?php } ?>

    What this says is if we are on the page with the numerical ID of 123 use pg-123.css and if not use the regular style sheet. If you want to do this for more than one page you will need to use elseif statements as well.

    What if you want to make the subpages of “123” in this code: <?php if ( is_page('123') ) { ?> to use the same style sheet? I have the conditional code working fine, but the subpages revert back to the default. Is there a way to make parent page (“123”) and all the subpages to it use the same style sheet, while the rest of the site uses the default?

    I created a separate template file (latin.php) to use on a page (latin) as well as a new header (latin_header.php) which calls a new style sheet (latin-style.css).

    The rest of the site uses the default (page.php; header.php; style.css).

    How can I get the page (latin) and any subpages to use the template file (latin.php)? By typing in the following code into header.php:

    <?php if (is_page(‘latin’)) { ?>
    <link rel=”stylesheet” href=”<?php bloginfo(‘template_url’); ?>/latin-style.css” type=”text/css”>
    <?php }; ?>`

    With this code, I can get the page (latin) to change its look.

    When I create subpages, I mark for them to use the “latin” template in the drop down menu on the right, but nothing changes. Also, if I take out the conditional code I posted and try to make the page (latin) use the template from the admin page, nothing works, it simply calls up the default page.php and looks like the rest of the site in color, banner, etc.

    Any thoughts on this? Is there code that can pull up all subpages to (latin)? Is there some reason that the templates do not come up when trying to use them from the admin and page editing/creation section?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Page-Specific Templates’ is closed to new replies.