[wp-hackers] get_template function

Ross Crawford ross.crawford at gmail.com
Sun Mar 19 23:49:57 GMT 2006


Hi,

I've added a new template to my theme to allow a sidebar on both sides. 
But while I was adding it, I thought the <?php include (TEMPLATEPATH . 
'/mytemplate.php'); ?> method is a bit clunky, and thought a better way 
would be the following:

function get_template($name) {
	if ( file_exists( TEMPLATEPATH . '/' . $name . '.php') )
		load_template( TEMPLATEPATH . '/' . $name . '.php');
	else{
		if ( file_exists( ABSPATH . 'wp-content/themes/default/' . $name . 
'.php') )
			load_template( ABSPATH . 'wp-content/themes/default/' . $name . '.php');
	}
}

Then change get_header() et al to:

function get_header() {
	get_template('header');
}

This would give a much nicer way to include user-defined templates, and 
avoid nasty errors when something is not right.

Comments?

ROSCO


More information about the wp-hackers mailing list