get_taxonomy_template

函式
get_taxonomy_template ( No parameters )
返回值
  • (string) Full path to custom taxonomy term template file.
相關
  • get_query_template()
定義位置
相關方法
get_tag_templateget_taxonomy_labelsget_home_templateget_category_templateget_author_template
引入
2.5.0
棄用
-

get_taxonomy_template: 這個函式檢索分類法檔案模板檔案的路徑。它接受一個引數:要檢索模板的分類法名稱。它以字串形式返回模板檔案的路徑。

在當前或父模板中檢索自定義分類法術語模板的路徑。

這個模板的層次結構看起來像:

1. taxonomy-{taxonomy_slug}-{term_slug}.php
2. taxonomy-{taxonomy_slug}.php
3. taxonomy.php

這方面的一個例子是:

1. taxonomy-location-texas.php
2. taxonomy-location.php
3. taxonomy.php

模板層次和模板路徑可通過{@see ‘$type_template_hierarchy’}和{@see ‘$type_template’}動態鉤子過濾。和{@see ‘$type_template’}動態鉤子,其中`$type`是’taxonomy’。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_taxonomy_template() {
$term = get_queried_object();
$templates = array();
if ( ! empty( $term->slug ) ) {
$taxonomy = $term->taxonomy;
$slug_decoded = urldecode( $term->slug );
if ( $slug_decoded !== $term->slug ) {
$templates[] = "taxonomy-$taxonomy-{$slug_decoded}.php";
}
$templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
$templates[] = "taxonomy-$taxonomy.php";
}
$templates[] = 'taxonomy.php';
return get_query_template( 'taxonomy', $templates );
}
function get_taxonomy_template() { $term = get_queried_object(); $templates = array(); if ( ! empty( $term->slug ) ) { $taxonomy = $term->taxonomy; $slug_decoded = urldecode( $term->slug ); if ( $slug_decoded !== $term->slug ) { $templates[] = "taxonomy-$taxonomy-{$slug_decoded}.php"; } $templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; $templates[] = "taxonomy-$taxonomy.php"; } $templates[] = 'taxonomy.php'; return get_query_template( 'taxonomy', $templates ); }
function get_taxonomy_template() {
	$term = get_queried_object();

	$templates = array();

	if ( ! empty( $term->slug ) ) {
		$taxonomy = $term->taxonomy;

		$slug_decoded = urldecode( $term->slug );
		if ( $slug_decoded !== $term->slug ) {
			$templates[] = "taxonomy-$taxonomy-{$slug_decoded}.php";
		}

		$templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
		$templates[] = "taxonomy-$taxonomy.php";
	}
	$templates[] = 'taxonomy.php';

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

常見問題

FAQs
檢視更多 >