get_page_templates

Definition:
function get_page_templates() {}

Get the Page Templates available in this theme

Return values

returns:Key is the template name, value is the filename of the template

Source code

function get_page_templates() {

	$themes = get_themes();

	$theme = get_current_theme();

	$templates = $themes[$theme]['Template Files'];

	$page_templates = array();



	if ( is_array( $templates ) ) {

		$base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );



		foreach ( $templates as $template ) {

			$basename = str_replace($base, '', $template);



			// don't allow template files in subdirectories

			if ( false !== strpos($basename, '/') )

				continue;



			if ( 'functions.php' == $basename )

				continue;



			$template_data = implode( '', file( $template ));



			$name = '';

			if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) )

				$name = _cleanup_header_comment($name[1]);



			if ( !empty( $name ) ) {

				$page_templates[trim( $name )] = $basename;

			}

		}

	}



	return $page_templates;

}

1546

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 )

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: