wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



get_single_template › WordPress Function

Seit1.5.0
Veraltetn/v
get_single_template ( Keine Parameter )
Siehe:
Gibt zurück:
  • (string) Full path to single template file.
Definiert in:
Codex:
Changelog:
  • 4.4.0
  • 4.7.0
  • 4.7.0

Retrieves path of single template in current or parent template. Applies to single Posts, single Attachments, and single custom post types.

The hierarchy for this template looks like: 1. {Post Type Template}.php 2. single-{post_type}-{post_name}.php 3. single-{post_type}.php 4. single.php An example of this is: 1. templates/full-width.php 2. single-post-hello-world.php 3. single-post.php 4. single.php The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'} and {@see '$type_template'} dynamic hooks, where $type is 'single'.


Quellcode

function get_single_template() {
	$object = get_queried_object();

	$templates = array();

	if ( ! empty( $object->post_type ) ) {
		$template = get_page_template_slug( $object );
		if ( $template && 0 === validate_file( $template ) ) {
			$templates[] = $template;
		}

		$name_decoded = urldecode( $object->post_name );
		if ( $name_decoded !== $object->post_name ) {
			$templates[] = "single-{$object->post_type}-{$name_decoded}.php";
		}

		$templates[] = "single-{$object->post_type}-{$object->post_name}.php";
		$templates[] = "single-{$object->post_type}.php";
	}

	$templates[] = 'single.php';

	return get_query_template( 'single', $templates );
}