get_post_type_archive_template

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

get_post_type_archive_template函式是一個WordPress函式,用於檢索指定文章型別的存檔模板檔案的路徑: 這個函式以文章型別名稱為引數,並返回指定文章型別的存檔模板檔案的路徑。

檢索當前或父模板中的文章型別存檔模板的路徑。

模板層次和模板路徑可通過{@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_post_type_archive_template() {
$post_type = get_query_var( 'post_type' );
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
}
$obj = get_post_type_object( $post_type );
if ( ! ( $obj instanceof WP_Post_Type ) || ! $obj->has_archive ) {
return '';
}
return get_archive_template();
}
function get_post_type_archive_template() { $post_type = get_query_var( 'post_type' ); if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); } $obj = get_post_type_object( $post_type ); if ( ! ( $obj instanceof WP_Post_Type ) || ! $obj->has_archive ) { return ''; } return get_archive_template(); }
function get_post_type_archive_template() {
	$post_type = get_query_var( 'post_type' );
	if ( is_array( $post_type ) ) {
		$post_type = reset( $post_type );
	}

	$obj = get_post_type_object( $post_type );
	if ( ! ( $obj instanceof WP_Post_Type ) || ! $obj->has_archive ) {
		return '';
	}

	return get_archive_template();
}

常見問題

FAQs
檢視更多 >