<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
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/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>WP Theming &#187; Thematic</title> <atom:link href="http://wptheming.com/category/thematic/feed/" rel="self" type="application/rss+xml" /><link>http://wptheming.com</link> <description>Tutorials, Themes and Plugins</description> <lastBuildDate>Tue, 31 Jan 2012 20:52:10 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Dynamic CSS Stylesheets and Thematic</title><link>http://wptheming.com/2009/12/dynamic-css-theme-options/</link> <comments>http://wptheming.com/2009/12/dynamic-css-theme-options/#comments</comments> <pubDate>Thu, 03 Dec 2009 04:44:03 +0000</pubDate> <dc:creator>Devin</dc:creator> <category><![CDATA[Thematic]]></category> <guid
isPermaLink="false">http://wordpresstheming.com/?p=491</guid> <description><![CDATA[A short tutorial describing how to make a dynamic stylesheet for use with Thematic.  <a
href="http://wordpresstheming.com/downloads/dynamic_child.zip">Source files</a> are also included. <a
href="http://wptheming.com/2009/12/dynamic-css-theme-options/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>A few weeks ago I wrote about using a <a
href="http://wptheming.com/2009/10/thematic-theme-options-panel/">theme options page</a> in Thematic to give users more control over their WordPress site.  To provide styling options for the theme, such as choice of fonts, text colors, and sidebar layouts- you&#8217;ll likely want to use a dynamic stylesheet in conjunction with the theme options.  So, here&#8217;s a short tutorial explaining how to do this and the <a
href="http://wptheming.com/downloads/dynamic_child.zip">source files for the child theme</a>.</p><h3>Dynamic CSS</h3><p>A dynamic stylesheet uses variables to define the css properties, which are set in the theme options.  When the stylesheet loads, it checks what&#8217;s set and then displays.</p><p>Jeremy Clark has a <a
href="http://clark-technet.com/2009/09/wordpress-theme-dev-tip-dynamic-stylesheets">great article about dynamic stylesheets</a> that explains how to set one up and how it works.  To get it running with the Thematic Framework just takes a few extra steps, especially if you&#8217;re already using the child theme I provided.  You may also be interested in <a
href="http://josephscott.org/archives/2010/03/database-powered-css-in-wordpress-themes/">this post</a> by Joesph Scott, which provides a few additional and possibly better methods.</p><h3>Create the Theme Options</h3><p>To start, let&#8217;s define theme options that will allow the user to set a background color and a font color.  We&#8217;ll just do this with a text field allowing them to paste in the HEX code (i know we could have a color wheel or something cool, but let&#8217;s just say a hex code for simplicity).  If you have the <a
href="http://wptheming.com/2009/10/thematic-theme-options-panel/">child theme</a> I set up, you would just add the following to the options array:</p><pre class="brush: php; first-line: 49; title: ; notranslate">
    array(
    'name' =&gt; 'Background Color #',
    'desc' =&gt; 'Paste in the HEX Code',
    'id' =&gt; $my_shortname . '_background',
    'std' =&gt; 'fff',
    'type' =&gt; 'text'
  ),
    array(
    'name' =&gt; 'Text Color #',
    'desc' =&gt; 'Paste in the HEX Code',
    'id' =&gt; $my_shortname . '_color',
    'std' =&gt; '111',
    'type' =&gt; 'text'
  ),
</pre><p>This should give you two new options in the panel:</p><p><a
href="http://wptheming.wpengine.netdna-cdn.com/wp-content/uploads/2009/12/theme-options.jpg"><img
src="http://wptheming.wpengine.netdna-cdn.com/wp-content/uploads/2009/12/theme-options.jpg" alt="theme-options" title="theme-options" width="480" height="196" class="alignnone size-full wp-image-498" /></a></p><h3>Create the Dynamic Stylesheet</h3><p>Now that options are set, we&#8217;ll need to create the stylesheet that calls these settings.  To set dynamic options and use variables you&#8217;ll need to use a .php file rather than a .css file.  I&#8217;d create a file called &#8220;dynamic-css.php&#8221; for this and put it with your other theme css files.</p><p>Inside the file, paste the following:</p><pre class="brush: php; title: ; notranslate">
&lt;?php
header('Content-type: text/css');
$css = $_GET[&quot;css&quot;];
$css = urldecode($css);
$cssoptions = explode(&quot;|&quot;, $css);
$background = $cssoptions[0];
$color = $cssoptions[1];
echo 'body {background-color:#'.$background.'; color:#'.$color.';}';
?&gt;
</pre><p>For an explanation of how this works, <a
href="http://clark-technet.com/2009/09/wordpress-theme-dev-tip-dynamic-stylesheets">see Jeremy Clark&#8217;s post</a> about this.</p><p>To send the variables from the theme options page to the stylesheet, and to link the stylesheet from the header you&#8217;ll need to paste the following into your Thematic child theme functions file:</p><pre class="brush: php; first-line: 28; title: ; notranslate">
/*
 * Call Dynamic Stylesheet
 */
function childtheme_dynamic_stylesheet($content) {
  $background = get_option('childtheme_background', 'fff');
  $color = get_option('childtheme_color', '111');
  $css = $background . '|' . $color;
  $content .= &quot;\t&quot;;
  $content .= '&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;' . get_bloginfo('stylesheet_directory') . '/css/dynamic-styles.php?css=' . $css .'&quot; /&gt;';
    $content .= &quot;\n\n&quot;;
  return $content;
}
add_filter('thematic_create_stylesheet', 'childtheme_dynamic_stylesheet');
</pre><p>I put this function inside the &#8220;admin-panel-functions.php&#8221; file I have in <a
href="http://wptheming.com/downloads/dynamic_child.zip">my child theme</a>.</p><h3>Original Look</h3><p><a
href="http://wptheming.wpengine.netdna-cdn.com/wp-content/uploads/2009/12/original-theme.jpg"><img
src="http://wptheming.wpengine.netdna-cdn.com/wp-content/uploads/2009/12/original-theme.jpg" alt="original-theme" title="original-theme" width="588" height="260" class="alignnone size-full wp-image-500" /></a></p><h3>New Options Set</h3><p><a
href="http://wptheming.wpengine.netdna-cdn.com/wp-content/uploads/2009/12/updated-options.jpg"><img
src="http://wptheming.wpengine.netdna-cdn.com/wp-content/uploads/2009/12/updated-options.jpg" alt="updated-options" title="updated-options" width="588" height="260" class="alignnone size-full wp-image-502" /></a></p><h3>Updated Look</h3><p><a
href="http://wptheming.wpengine.netdna-cdn.com/wp-content/uploads/2009/12/new-theme.jpg"><img
src="http://wptheming.wpengine.netdna-cdn.com/wp-content/uploads/2009/12/new-theme.jpg" alt="new-theme" title="new-theme" width="588" height="260" class="alignnone size-full wp-image-503" /></a></p><h3><a
href="http://wptheming.com/downloads/dynamic_child.zip">Download the Source</a></h3><p>I wrapped everything into an updated version of <a
href="http://wptheming.com/downloads/dynamic_child.zip">the child theme</a> that you are welcome to use however you want.  Let me know if you make any improvements.</p><p>And if you&#8217;re interested in these sort of things, <a
href="http://twitter.com/devinsays">follow me on twitter</a> or <a
href="http://feeds.feedburner.com/wordpress-theming">subscribe to the rss feed</a>.</p> ]]></content:encoded> <wfw:commentRss>http://wptheming.com/2009/12/dynamic-css-theme-options/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> </channel> </rss>
