Advertisements

get_page_template

Definition:
function get_page_template() {}

Retrieve path of page template in current or parent template.
Will first look for the specifically assigned page template The will search for ‘page-{slug}.php’ followed by ‘page-id.php’ and finally ‘page.php’

Source code

function get_page_template() {

	$id = get_queried_object_id();

	$template = get_post_meta($id, '_wp_page_template', true);

	$pagename = get_query_var('pagename');



	if ( !$pagename && $id > 0 ) {

		// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object

		$post = get_queried_object();

		$pagename = $post->post_name;

	}



	if ( 'default' == $template )

		$template = '';



	$templates = array();

	if ( !empty($template) && !validate_file($template) )

		$templates[] = $template;

	if ( $pagename )

		$templates[] = "page-$pagename.php";

	if ( $id )

		$templates[] = "page-$id.php";

	$templates[] = 'page.php';



	return get_query_template( 'page', $templates );

}

1544

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: