Dynamic Stylesheet
-
Hey all,
I was helping out someone with their WordPress site – she’s setting it up for a friend of hers. There was a need to have a different background to be set for every Page you come to on the site. Now, I know you can accomplish this by creating a page template or by using a conditional, but the problem is that the lady who the site is for isn’t very computer literate (and thus would have no clue how to create a new page template and/or add in the necessary stuff for conditionals).
Now, I know you can create a dynamic stylesheet (I’ve done it before), so the idea was to add a dynamic stylesheet to pull in the page slug of the current page you’re one, and use that as the image that would be set for the background. The odd thing is that the stylesheet.php file seems to be stripping out the ability to read what Page you’re on. *Outside* of “stylesheet.php” if I use this code:
$dpname = $post->post_name; echo $dpname;
The the slug of the Page you’re on will display. We were going to use this to set the background image:
body { background-image:url("../images/<?php echp $dpname; ?>_bg.gif); }
As I said, the above works fine in any other file in the system. However, when I put it in an actual stylesheet.pph file, the $dpname is ignored, and never gets called in. I’m *suspecting* it’s because of this line in the stylesheet (which *must* appear at the top of the file for it to work as a stylesheet):
header(‘Content-Type=text/css’);
I don’t know enough about dynamic stylesheets to know if this truly is the cause. But I’m really suspecting that it is.
Does anyone know if this *is* what’s stripping the PHP from the file? And if so, would anyone know what I need to do to keep it recognizable as a stylesheet, but still pull in the information that I need?
- The topic ‘Dynamic Stylesheet’ is closed to new replies.