Un motore di ricerca WordPress per sviluppatori e autori di temi



locate_template ›

Da2.7.0
Deprecaton/a
locate_template ( $template_names, $load = false, $require_once = true )
Parametri: (3)
  • (string|array) $template_names Template file(s) to search for, in order.
    Richiesto:
  • (bool) $load If true the template file will be loaded if it is found.
    Richiesto: No
    Default: false
  • (bool) $require_once Whether to require_once or require. Default true. Has no effect if $load is false.
    Richiesto: No
    Default: true
Ritorna:
  • (string) The template filename if one is located.
Definito a:
Codex:

Retrieve the name of the highest priority template file that exists.

Searches in the STYLESHEETPATH before TEMPLATEPATH and wp-includes/theme-compat so that themes which inherit from a parent theme can just overload one file.



Sorgenti

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;
		} elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) {
			$located = TEMPLATEPATH . '/' . $template_name;
			break;
		} elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
			$located = ABSPATH . WPINC . '/theme-compat/' . $template_name;
			break;
		}
	}

	if ( $load && '' != $located ) {
		load_template( $located, $require_once );
	}

	return $located;
}