get_category_template

函式
get_category_template ( No parameters )
返回值
  • (string) Full path to category template file.
相關
  • get_query_template()
定義位置
相關方法
get_author_templateget_date_templateget_query_templateget_tag_templateget_page_template
引入
1.5.0
棄用
-

get_category_template: 這個函式檢索應該用於顯示給定類別的模板檔案。

檢索當前或父模板中的類別模板的路徑。

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

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

這方面的一個例子是:

1. category-news.php
2. category-2.php
3. category.php

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

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

	$templates = array();

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

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

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

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

常見問題

FAQs
檢視更多 >