Advertisements

locate_template

Definition:
function locate_template($template_names, $load = false, $require_once = true ) {}

Retrieve the name of the highest priority template file that exists.
Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which inherit from a parent theme can just overload one file.

Parameters

  • string|array $template_names: Template file(s) to search for, in order.
  • bool $load: If true the template file will be loaded if it is found.
  • bool $require_once: Whether to require_once or require. Default true. Has no effect if $load is false.

Return values

returns:The template filename if one is located.

Source code

function locate_template($template_names, $load = false, $require_once = true ) {

	$located = '';

	foreach ( (array) $template_names as $template_name ) {

		if ( !$template_name )

			continue;

		if ( file_exists(STYLESHEETPATH . '/' . $template_name)) {

			$located = STYLESHEETPATH . '/' . $template_name;

			break;

		} else if ( file_exists(TEMPLATEPATH . '/' . $template_name) ) {

			$located = TEMPLATEPATH . '/' . $template_name;

			break;

		}

	}



	if ( $load && '' != $located )

		load_template( $located, $require_once );



	return $located;

}

2297

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: