PHP in CSS using $thisPage

I’m looking to use PHP in my CSS to change css selectors depending on the page name. What I have is a number of main php files with this code:


<?php $thisPage="Home"; ?>
<?php include('content/bod_header.php'); ?>
</head>

Depending on the page $thisPage=“Home” might be “About Us” “Shop” etc.
bod_header.php contains a number of shared css and js files:


<link rel="stylesheet" href="css/layout.php" media="screen" type="text/css" />
<link rel="stylesheet" href="css/print.css" media="print" type="text/css" />

So far I put in some php into my layout style sheet but it hasn’t acted like a css file when I go to try it out on the server and it is also missing any if statements for $thisPage variable:


<?php 
header("Content-type: text/css");
$header_w = "928px"; 
$header_h = "318px"; 
$header_bg = "no-repeat 926 1415"; 
echo <<<CSS 
.header{z-index:0;margin-top:1px;width:<?=$header_w?>;height:<?=$header_h?>;background:url(img/all.png)<?=$header_bg?>}
CSS;
?>

I was planing on using a code like this to call in the $thisPage if statement but since I can’t get the php file to act like a css I’m not sure what will work for what I’m looking for.


if ($thisPage=="About Us") 
      echo $header_w = "928px";

Put an id tag on <body> and call it a day.


<body id="<?php echo $this->page ?>">

Then in your CSS file - a normal CSS file with no PHP mind you - you can apply the styling elements you need against that id.


.header {
// default styling of .header
}
#AboutUs .header {
// styling for .header in the #AboutUs page.
}

#ContactUs .header {
// styling for contact us
}

And so on…