get_author_template

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

get_author_template: 這個函式檢索到當前主題的作者模板的路徑。

在當前或父模板中檢索作者模板的路徑。

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

1. author-{nicename}.php
2. author-{id}.php
3. author.php

這方面的一個例子是:

1. author-john.php
2. author-1.php
3. author.php

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_author_template() {
$author = get_queried_object();
$templates = array();
if ( $author instanceof WP_User ) {
$templates[] = "author-{$author->user_nicename}.php";
$templates[] = "author-{$author->ID}.php";
}
$templates[] = 'author.php';
return get_query_template( 'author', $templates );
}
function get_author_template() { $author = get_queried_object(); $templates = array(); if ( $author instanceof WP_User ) { $templates[] = "author-{$author->user_nicename}.php"; $templates[] = "author-{$author->ID}.php"; } $templates[] = 'author.php'; return get_query_template( 'author', $templates ); }
function get_author_template() {
	$author = get_queried_object();

	$templates = array();

	if ( $author instanceof WP_User ) {
		$templates[] = "author-{$author->user_nicename}.php";
		$templates[] = "author-{$author->ID}.php";
	}
	$templates[] = 'author.php';

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

常見問題

FAQs
檢視更多 >