tags:

views:

82

answers:

4

I have a (probably not) unique issue with a css background div I am seeking advice on. I am using Wordpress, which creates my pages dynamically. The front page and some other pages are using one type of background (Gradient) while internal pages are using a solid white. Right now I am forced to have two style sheets - main.css for the gradient background, then internal.css for the internal - just for this background div.

Is there a way to use one css file and handle these two background divs easily? I will probably need to use a bit of php...

Essentially I am only trying to pass two different background divs, on either home or some internal pages.

A: 

'; } else { echo ''; } ?>

64vision
If you tried to paste a snippet here, it didn't work.
Tim Post
A: 

You could use your normal stylsheet on all the pages, with the solid white background set. Then on your front page and other 'special' pages, you could have a tag with the background image that will override the white:

<head>
<link rel="stylesheet" type="text/css" href="main.css" /><!-- This has background-color:white; -->
<?php if(!empty($special)){
echo <<<HTML
    <style>
    body{
        background-color:transparent;
        background-image:url('image_url');
    }
    </style>
HTML;
?>
</head>

Then you'd just set $special to true or something when you're on a 'special' page.

BraedenP
Thanks for your help! In Wordpress, since it generates the pages dynamically, how would i assign the 'special' pages?
HollerTrain
+2  A: 

Just use different template files (which you should be doing anyway because of the different looks), and use something like an ID on the body tag to check like this:

<body id="grad">
    ...
</body>

or

<body id="white">
    ...
</body>

And use this in your stylesheet:

#grad {
    background-image:url(something.png);
}
#white {
    background-color:#FFF;
}

Make sure to check out the template hierarchy page in the WordPress codex to see how you can easily create the template files you need. Use #grad in home.php and/or a custom template file that you apply to your front page (if it's static), and then use #while in everything else (category.php, tag.php, single.php, and page.php are probably the basics).

Aaron D. Campbell
how would this work if the header is the file that display the body tag?
HollerTrain
A: 

I didn't think of this but here is the code:

<body<?php if ( !is_home() ) echo ' style="background-image: url(images/about_bg.png);"'; ?>>

Put it in the header.

HollerTrain