I'm building a CMS, and I'm trying to figure out how to create a framework whereby I identify things like heights, widths, backgrounds, etc. that match the specs used on the public site so that the administrators "see" what their photo galleries, etc are going to look like on the website. For example, I use floated DIV's instead of tables to organize photo album thumbnails, which opens up the ability for me to put jQuery's sortable() function into the CMS part without having two different layouts (TABLE vs OL) on the admin and public pages.

Can something like this be done for CSS files? How about using multiple classes like Wordpress does (which I hate, but it seems to be effective)?

I could always do inline styling but that's so messy.

2 answers



header("Content-type: text/css");  
$color1 = "#000";
$color2 = "#fff";
body {
    background-color: <?php echo $color1; ?>;
h1 {
    color: <?php echo $color2; ?>;

Include your dynamic css something like this:

<link href="styles.css.php" media="screen" rel="stylesheet" type="text/css" />
Answered over 9 years ago by Dwayne Anderson
  • We should point out the downside of PHP generated CSS, in that the usual caching of CSS files by the browser is lost. Tony Crockford over 9 years ago
  • I was curious about that, actually. Stephan Hovnanian over 9 years ago
  • a workaround for that would be for the to have a "normal" css file that is generated by php only when changes are made... Dwayne Anderson over 9 years ago
  • Web servers do not automatically send caching information when serving PHP files, but the PHP file in question can easily be coded to output the appropriate caching headers, just like it outputs the "content-type" header in this example. Doug over 9 years ago

why not link from the CMS to a preview page that just pulls in the site CSS for formatting the layout?

if you really want PHP powered CSS this would be a good start:


Answered over 9 years ago by Tony Crockford
  • the preview page, in conjunction with using more than one class per item, would probably do the trick. and thanks for the link, looks like a good start as you said. Stephan Hovnanian over 9 years ago