get_archive_template

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

get_archive_template: 這個函式返回當前文章型別的存檔模板檔案的路徑。如果沒有找到模板,它返回一個空字串。

檢索當前或父模板中的存檔模板路徑。

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_archive_template() {
$post_types = array_filter( (array) get_query_var( 'post_type' ) );
$templates = array();
if ( count( $post_types ) == 1 ) {
$post_type = reset( $post_types );
$templates[] = "archive-{$post_type}.php";
}
$templates[] = 'archive.php';
return get_query_template( 'archive', $templates );
}
function get_archive_template() { $post_types = array_filter( (array) get_query_var( 'post_type' ) ); $templates = array(); if ( count( $post_types ) == 1 ) { $post_type = reset( $post_types ); $templates[] = "archive-{$post_type}.php"; } $templates[] = 'archive.php'; return get_query_template( 'archive', $templates ); }
function get_archive_template() {
	$post_types = array_filter( (array) get_query_var( 'post_type' ) );

	$templates = array();

	if ( count( $post_types ) == 1 ) {
		$post_type   = reset( $post_types );
		$templates[] = "archive-{$post_type}.php";
	}
	$templates[] = 'archive.php';

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

常見問題

FAQs
檢視更多 >