<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Dynamic CSS A.K.A. CSS Variables</title>
	<atom:link href="http://www.silverspider.com/2007/dynamic-css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.silverspider.com/2007/dynamic-css/</link>
	<description>Refresh&#160;Austin ringleader, speaker, fire starter, UX manager, community catalyst, Web technologist, barbecue acolyte &#38; information junkie</description>
	<lastBuildDate>Sat, 27 Feb 2010 15:11:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: CSS Wishlist: New Ideas, Debates and Solutions - Smashing Magazine</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-51389</link>
		<dc:creator>CSS Wishlist: New Ideas, Debates and Solutions - Smashing Magazine</dc:creator>
		<pubDate>Wed, 18 Nov 2009 20:13:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-51389</guid>
		<description>[...]  [...]</description>
		<content:encoded><![CDATA[<p>[...]  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: micharo</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-44569</link>
		<dc:creator>micharo</dc:creator>
		<pubDate>Wed, 22 Oct 2008 04:42:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-44569</guid>
		<description>thanks so much for writing back!

Here is a little bit more info:


What I want to do:
I have website with a few main pages and sub pages and sub sub pages. Each area (each main page is an area with some sub pages) has a different color background. In other words a main page and the children (sub pages) have the same background, but each area is different. The color value of the area&#039;s background is stored in a custom field in each main page.

So I wrote a style_dynamic.php with the following blocks in it.
- first I require wp-blog-header.php
- then with a function I get the color value from the custom field of the main page or if it is a child from the top parent (main page)
- then I declare this php file as a css header(&#039;Content-type: text/css&#039;);
- then I write the css style with the variable

The problem:
It seems the color value is retrieved from the custom field but somehow not read by the css.



&amp;lt?php
require(&#039;../../../wp-blog-header.php&#039;);

function get_color_value(){
global $post;
	if(is_page() &amp;&amp; $post-&amp;gtpost_parent){//if the current post is a page and has a parent, then: 
	
		$parent_id = $post-&amp;gtpost_parent; // assign the id of the parent
		$parent_post = get_post($parent_id); //get the parent post
		
		// if current page is in the sub sub level or deeper nested											
		while($parent_post-&amp;gtpost_parent){ // if the parent post has a parent, then
			$parent_id = $parent_post-&amp;gtpost_parent;
			$parent_post = get_post($parent_id);
		}
	
	}else{
		$parent_id = $post-&gtID; //if it doesn&#039;t have a parent, it must be a parent, so its own ID gets stored as $parent.
	}
	
	$key = &quot;bg_color&quot;;
	$single = true;
	$post_id = $parent_id;
	$color_value .= get_post_meta($post_id, $key, $single);
		
	return $color_value;
}
$color = get_color_value();

	
// declare the output of the file as CSS
header(&#039;Content-type: text/css&#039;); 

?&amp;gt
#headerBg {
background-color: &amp;lt?=$color?&gt;
}</description>
		<content:encoded><![CDATA[<p>thanks so much for writing back!</p>
<p>Here is a little bit more info:</p>
<p>What I want to do:<br />
I have website with a few main pages and sub pages and sub sub pages. Each area (each main page is an area with some sub pages) has a different color background. In other words a main page and the children (sub pages) have the same background, but each area is different. The color value of the area&#8217;s background is stored in a custom field in each main page.</p>
<p>So I wrote a style_dynamic.php with the following blocks in it.<br />
- first I require wp-blog-header.php<br />
- then with a function I get the color value from the custom field of the main page or if it is a child from the top parent (main page)<br />
- then I declare this php file as a css header(&#8216;Content-type: text/css&#8217;);<br />
- then I write the css style with the variable</p>
<p>The problem:<br />
It seems the color value is retrieved from the custom field but somehow not read by the css.</p>
<p>&amp;lt?php<br />
require(&#8216;../../../wp-blog-header.php&#8217;);</p>
<p>function get_color_value(){<br />
global $post;<br />
	if(is_page() &amp;&amp; $post-&amp;gtpost_parent){//if the current post is a page and has a parent, then: </p>
<p>		$parent_id = $post-&amp;gtpost_parent; // assign the id of the parent<br />
		$parent_post = get_post($parent_id); //get the parent post</p>
<p>		// if current page is in the sub sub level or deeper nested<br />
		while($parent_post-&amp;gtpost_parent){ // if the parent post has a parent, then<br />
			$parent_id = $parent_post-&amp;gtpost_parent;<br />
			$parent_post = get_post($parent_id);<br />
		}</p>
<p>	}else{<br />
		$parent_id = $post-&gtID; //if it doesn&#8217;t have a parent, it must be a parent, so its own ID gets stored as $parent.<br />
	}</p>
<p>	$key = &#8220;bg_color&#8221;;<br />
	$single = true;<br />
	$post_id = $parent_id;<br />
	$color_value .= get_post_meta($post_id, $key, $single);</p>
<p>	return $color_value;<br />
}<br />
$color = get_color_value();</p>
<p>// declare the output of the file as CSS<br />
header(&#8216;Content-type: text/css&#8217;); </p>
<p>?&amp;gt<br />
#headerBg {<br />
background-color: &amp;lt?=$color?&gt;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-44376</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Mon, 20 Oct 2008 13:15:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-44376</guid>
		<description>Hi Micharo, can you provide a little more information what isn&#039;t working right? 

Also, it looks like some of the code you entered here was stripped by WordPress for security. Please make sure that you escape all less than and greater than signs (&lt; and &gt;) to ensure the code stays whole.</description>
		<content:encoded><![CDATA[<p>Hi Micharo, can you provide a little more information what isn&#8217;t working right? </p>
<p>Also, it looks like some of the code you entered here was stripped by WordPress for security. Please make sure that you escape all less than and greater than signs (&amp;lt; and &amp;gt;) to ensure the code stays whole.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: micharo</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-44317</link>
		<dc:creator>micharo</dc:creator>
		<pubDate>Sun, 19 Oct 2008 16:34:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-44317</guid>
		<description>Sorry, here is the full code

&lt;code&gt;post_parent){//if the current post is a page and has a parent, then: 
	
		$parent_id = $post-&gt;post_parent; // assign the id of the parent
		$parent_post = get_post($parent_id); //get the parent post
		
		// if current page is in the sub sub level or deeper nested											
		while($parent_post-&gt;post_parent){ // if the parent post has a parent, then
			$parent_id = $parent_post-&gt;post_parent;
			$parent_post = get_post($parent_id);
		}
	
	}else{
		$parent_id = $post-&gt;ID; //if it doesn&#039;t have a parent, it must be a parent, so its own ID gets stored as $parent.
	}
	
	$key = &quot;bg_color&quot;;
	$single = true;
	$post_id = $parent_id;
	$color_value .= get_post_meta($post_id, $key, $single);
		
	return $color_value;
}
$color = get_color_value();

	
// declare the output of the file as CSS
header(&#039;Content-type: text/css&#039;); 

?&gt;
#headerBg {
background-color: ;
}&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Sorry, here is the full code</p>
<p><code>post_parent){//if the current post is a page and has a parent, then: </p>
<p>		$parent_id = $post-&gt;post_parent; // assign the id of the parent<br />
		$parent_post = get_post($parent_id); //get the parent post</p>
<p>		// if current page is in the sub sub level or deeper nested<br />
		while($parent_post-&gt;post_parent){ // if the parent post has a parent, then<br />
			$parent_id = $parent_post-&gt;post_parent;<br />
			$parent_post = get_post($parent_id);<br />
		}</p>
<p>	}else{<br />
		$parent_id = $post-&gt;ID; //if it doesn't have a parent, it must be a parent, so its own ID gets stored as $parent.<br />
	}</p>
<p>	$key = "bg_color";<br />
	$single = true;<br />
	$post_id = $parent_id;<br />
	$color_value .= get_post_meta($post_id, $key, $single);</p>
<p>	return $color_value;<br />
}<br />
$color = get_color_value();</p>
<p>// declare the output of the file as CSS<br />
header('Content-type: text/css'); </p>
<p>?&gt;<br />
#headerBg {<br />
background-color: ;<br />
}</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: micharo</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-44316</link>
		<dc:creator>micharo</dc:creator>
		<pubDate>Sun, 19 Oct 2008 16:32:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-44316</guid>
		<description>I got the template functions to work, but still something is not doing right.

&lt;code&gt;post_parent){//if the current post is a page and has a parent, then: 
	
		$parent_id = $post-&gt;post_parent; // assign the id of the parent
		$parent_post = get_post($parent_id); //get the parent post
		
		// if current page is in the sub sub level or deeper nested											
		while($parent_post-&gt;post_parent){ // if the parent post has a parent, then
			$parent_id = $parent_post-&gt;post_parent;
			$parent_post = get_post($parent_id);
		}
	
	}else{
		$parent_id = $post-&gt;ID; //if it doesn&#039;t have a parent, it must be a parent, so its own ID gets stored as $parent.
	}
	
	$key = &quot;bg_color&quot;;
	$single = true;
	$post_id = $parent_id;
	$color_value .= get_post_meta($post_id, $key, $single);
		
	return $color_value;
}
$color = get_color_value();

	
// declare the output of the file as CSS
header(&#039;Content-type: text/css&#039;); 

?&gt;
#headerBg {
background-color: ;
}
&lt;/code&gt;

Help appreciated!</description>
		<content:encoded><![CDATA[<p>I got the template functions to work, but still something is not doing right.</p>
<p><code>post_parent){//if the current post is a page and has a parent, then: </p>
<p>		$parent_id = $post-&gt;post_parent; // assign the id of the parent<br />
		$parent_post = get_post($parent_id); //get the parent post</p>
<p>		// if current page is in the sub sub level or deeper nested<br />
		while($parent_post-&gt;post_parent){ // if the parent post has a parent, then<br />
			$parent_id = $parent_post-&gt;post_parent;<br />
			$parent_post = get_post($parent_id);<br />
		}</p>
<p>	}else{<br />
		$parent_id = $post-&gt;ID; //if it doesn't have a parent, it must be a parent, so its own ID gets stored as $parent.<br />
	}</p>
<p>	$key = "bg_color";<br />
	$single = true;<br />
	$post_id = $parent_id;<br />
	$color_value .= get_post_meta($post_id, $key, $single);</p>
<p>	return $color_value;<br />
}<br />
$color = get_color_value();</p>
<p>// declare the output of the file as CSS<br />
header('Content-type: text/css'); </p>
<p>?&gt;<br />
#headerBg {<br />
background-color: ;<br />
}<br />
</code></p>
<p>Help appreciated!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: micharo</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-44315</link>
		<dc:creator>micharo</dc:creator>
		<pubDate>Sun, 19 Oct 2008 16:05:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-44315</guid>
		<description>Hi,

I try read a custom field (background color) from a page and use that value in a dynamic cssStyle.php.

But if I add a template function in the cssStyle.php like get_post() it does not work.
I assume the problem is that the cssStyle.php is called in the header and template functions are not available.

Any help appreciated!</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I try read a custom field (background color) from a page and use that value in a dynamic cssStyle.php.</p>
<p>But if I add a template function in the cssStyle.php like get_post() it does not work.<br />
I assume the problem is that the cssStyle.php is called in the header and template functions are not available.</p>
<p>Any help appreciated!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gavin</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-38953</link>
		<dc:creator>gavin</dc:creator>
		<pubDate>Mon, 18 Aug 2008 02:41:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-38953</guid>
		<description>... and if you want to get crazy and take all the extra whitespace out of your css, click here:

http://websitetips.com/articles/optimization/css/crunch/</description>
		<content:encoded><![CDATA[<p>&#8230; and if you want to get crazy and take all the extra whitespace out of your css, click here:</p>
<p><a href="http://websitetips.com/articles/optimization/css/crunch/" rel="nofollow">http://websitetips.com/articles/optimization/css/crunch/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gavin</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-38952</link>
		<dc:creator>gavin</dc:creator>
		<pubDate>Mon, 18 Aug 2008 02:34:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-38952</guid>
		<description>thanks.  By the way, you can remove CSS comments by adding this code to the script I posted before:

$file_contents  = preg_replace(&#039;!/\*[^*]*\*+([^/][^*]*\*+)*/!&#039;, &#039;&#039;, $file_contents); // removes comments from css</description>
		<content:encoded><![CDATA[<p>thanks.  By the way, you can remove CSS comments by adding this code to the script I posted before:</p>
<p>$file_contents  = preg_replace(&#8216;!/\*[^*]*\*+([^/][^*]*\*+)*/!&#8217;, &#8221;, $file_contents); // removes comments from css</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-38806</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 16 Aug 2008 13:22:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-38806</guid>
		<description>Great idea Gavin! I didn&#039;t want to treat all CSS as PHP, adding needless overhead, but I hadn&#039;t thought about a local .htaccess file. 

Very smart, thanks for sharing it!</description>
		<content:encoded><![CDATA[<p>Great idea Gavin! I didn&#8217;t want to treat all CSS as PHP, adding needless overhead, but I hadn&#8217;t thought about a local .htaccess file. </p>
<p>Very smart, thanks for sharing it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gavin</title>
		<link>http://www.silverspider.com/2007/dynamic-css/comment-page-1/#comment-38790</link>
		<dc:creator>gavin</dc:creator>
		<pubDate>Sat, 16 Aug 2008 10:14:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.silverspider.com/2007/dynamic-css/#comment-38790</guid>
		<description>Wonderful article, and your blog looks great.

Am I seeing that you name all your css files with a .php extension?  If you want to keep you .css extension and use php tags in them, try this:

&lt;pre&gt;&lt;code&gt;/css/.htaccess:
RewriteEngine on
RewriteRule \.(.*)$ dynamic_css.php [L]

/css/dynamic_css.php:
if ($file_name = basename($_SERVER[&#039;REQUEST_URI&#039;])) {
    header(&#039;Content-type: text/css&#039;);
    eval(&#039;?&gt;&#039;.file_get_contents($file_name));
}   &lt;/code&gt;&lt;/pre&gt;


Of course it means adding 2 new files to your css folder.  But it makes dynamic-css files transparent to the rest of your application.</description>
		<content:encoded><![CDATA[<p>Wonderful article, and your blog looks great.</p>
<p>Am I seeing that you name all your css files with a .php extension?  If you want to keep you .css extension and use php tags in them, try this:</p>
<pre><code>/css/.htaccess:
RewriteEngine on
RewriteRule \.(.*)$ dynamic_css.php [L]

/css/dynamic_css.php:
if ($file_name = basename($_SERVER['REQUEST_URI'])) {
    header('Content-type: text/css');
    eval('?&gt;'.file_get_contents($file_name));
}   </code></pre>
<p>Of course it means adding 2 new files to your css folder.  But it makes dynamic-css files transparent to the rest of your application.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
