Dynamically Generate Static CSS with PHP
-
Topic
-
I’m a huge fan of Jason’s work, and having the ability to create a child theme on some of his stuff is going to be fun. First, in my child theme I want to create a dynamic stylesheet which retrieves values from the options panel. I’ve used the same process with my Genesis child theme and NHP, works amazing. So I thought i’d try it out with Jason’s awesome new framework. Aquagraphite outlines one of the popular ways to do this at http://aquagraphite.com/2011/11/dynamically-generate-static-css-files-using-php/. I have created a custom options.php file in my child theme’s assets folder. Here is the code for the options I added:
Next, I created a style.php file inside my assets folder and copied the contents of the style.css into the .php file. I used
<?php echo themeblvd_get_option( 'text_color' ); ?>
to pull the options I wanted for each area. Ref:Finally, I created my functions.php file to automatically generate a new .css file and enqueue it:
So far the code works great. My child theme automatically generates a new .css file from my .php file! There is one issue though; the option values aren’t showing up in my .css file!? Now I’m not familiar with the theme options kit, so I’m going to ask from my experience using Lee Mason’s NHP Options (http://leemason.github.com/NHP-Theme-Options-Framework/). To retrieve value for this you need to make sure you include the options framework, in the case of NHP you would use:
<?php $options = get_option('option_name'); ?>
Jason, do I need to add something like:
<?php get_options( 'themeblvd' ); ?>
to retrieve the options values for my options.php? Thanks for the help!
- You must be logged in to reply to this topic.