Archive for the 'guides' Category

WordPress Theme Developers Tip – Call Dynamic CSS the Right Way

Monday, January 25th, 2010

While developing my Techozoic theme, I’ve progressed from adding custom CSS into the head section, to having an external file and using $_GET variables to pull options from the database, to now I believe is the right way to do it, using add_filter and a custom query in WordPress. By using this new method I’ve done away with unsafe $_GET variables and can now use any builtin WP functions in the external file.
First you’ll need to edit your functions.php file and add this block of code.

	add_filter('query_vars', 'add_new_var_to_wp');
	function add_new_var_to_wp($public_query_vars) {
		$public_query_vars[] = 'my_theme_custom_var';
		//my_theme_custom_var is the name of the custom query variable that is created and how you reference it in the call to the file
		return $public_query_vars;
	}

This sets up WP to now accept a new variable in a query called my_theme_custom_var the format of the query would be http://www.yourblog.com/index.php?my_theme_custom_var=css . The ? mark tells WP that this is a query and the = sign tells what the query variable should be set to.
Now to actually setup the function that will call the external file. I found this gem when looking at how popular WP theme called Atahualpa handled it’s external CSS.

	add_action('template_redirect', 'my_theme_css_display');
	function my_theme_css_display(){
		$css = get_query_var('my_theme_custom_var');
		if ($css == 'css'){
			include_once (TEMPLATEPATH . '/style.php');
			exit;  //This stops WP from loading any further
		}
	}

This code now will check if a query is passed to WP with the value my_theme_custom_var and if it is and has the value of css then it includes the style.php file which is our dynamic CSS file. Then the code exits which stops any other functions from happening other wise the whole home page is outputted along with the style.php file, which isn’t what is needed only the file.
Now you can use any WP functions on the style.php file as it is included from the functions.php file which is a standard WP file.
Source : Will Norris

Tags: , ,

Wordpress Theme Options Framework Ver 2

Tuesday, January 12th, 2010

As I’ve worked more on my theme and increased my coding skills I’ve added to my original theme option framework. I’ve become more aware of best practices of coding and WordPress, a big issue with the original framework was the way options were added to the wp_options database table. Each theme option got it’s own entry in the table, this might be okay for small theme, but I’ve grown to over 40 different options in my Techozoic theme. It was time to optimize, with the new framework the entries added to the wp_options table went from 40 to 2. I’ll continue below with code examples and explanations. As an added bonus I’ve included an example of how to pull your theme options into a external stylesheet, based off of this concept.

(more…)

Tags: , , ,

Wordpress 2.7 Comment Threading

Wednesday, October 1st, 2008

Thanks to Otto for this great post on the heads up on the new comment system for WordPress 2.7. After I read this I decided to get ahead of the curve and switch my Techozoic theme over to the new threaded commenting. I decided to take it a little further and separate pings and trackbacks from regular comments. At first this wasn’t working but after a quick email to the wp-testers list Ryan whipped up a fix for it. Anyway I figured I would explain how I did this. I continue below.

(more…)

Tags: , , , ,

Another New Linux Guide Page

Monday, September 29th, 2008


Unlocking Locked Network Files

Although this one is short I think it could be very useful to those that need it. It doesn’t come up often but when it does it’s extremely frustrating.

Tags: , ,

WordPress Theme Options Framework

Friday, September 12th, 2008

Update: New Version

I’ve released a newly optimized version of the Theme Options Framework that now only makes two calls to the database rather than one call per option.

Recently I’ve been doing alot of work on my themes. I started off with the idea to make my theme work user friendly by adding a options page. So I started looking for how to do this, and came across this page and some useful code. So I took this and started modifying and trying different things and now I think I’ve got a very useful framework and I wanted to share with others. I’ll continue below as this will be fairly long post.

(more…)

Tags: , , ,