Forum Moderators: coopster
However, the person I was helping needed the variables to also be dynamic. They were using a CMS system, and needed the variables to be based on article titles.
So, for example, they had an article titled "spoons". The dynamic CSS would use the article title to set the background image for that article, so it would do:
body {background-image:url('../images/spoons.gif');
What I did was place a piece of code in the dynamic stylesheet so that it would see whatever page it was on, and use that page name/article title and use it as the name of the image to be pulled in.
The code looked liek so:
<?php
header('Content-type: text/css');
global $post;
$dpname = $post->post_name;
?>
body { background-image:url("../images/<?php echo $dpname;?>_bg.jpg"); }
(For the record, she's using WordPress, and "$post_>post_name" is what pulls the title of the article from the database and displays it as a variable)
IN any other PHP page, I can use that code, and it will spit out *exactly* what I need. However, in this file, it will not. $dpname always returns as empty.
I'm *suspecting* it's because of the "header('Content-type: text/css');" line - that this is stripping everything down to text-only. But that seems odd to me, because if I hard-code the variables in there, it pulls it through just fine.
Would anyone happen to know *why* the variables are getting stripped? Even better - know how to fix it?