get_tag_template

函式
get_tag_template ( No parameters )
返回值
  • (string) Full path to tag template file.
相關
  • get_query_template()
定義位置
相關方法
get_page_templateget_page_templatesget_paged_templateget_templateget_date_template
引入
2.3.0
棄用
-

get_tag_template: 這個函式檢索到標籤存檔模板檔案的路徑。它不接受任何引數,並以字串形式返回模板檔案的路徑。

在當前或父模板中檢索標籤模板的路徑。

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

1. tag-{slug}.php
2. tag-{id}.php
3. tag.php

這方面的一個例子是:

1. tag-wordpress.php
2. tag-3.php
3. tag.php

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

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

	$templates = array();

	if ( ! empty( $tag->slug ) ) {

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

		$templates[] = "tag-{$tag->slug}.php";
		$templates[] = "tag-{$tag->term_id}.php";
	}
	$templates[] = 'tag.php';

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

常見問題

FAQs
檢視更多 >