post_type_archive_title

函式
post_type_archive_title ( $prefix = '', $display = true )
引數
  • (string) $prefix Optional. What to display before the title.
    Required:
    Default: (empty)
  • (bool) $display Optional. Whether to display or retrieve title. Default true.
    Required:
    Default: true
返回值
  • (string|void) Title when retrieving, null when displaying or failure.
定義位置
相關方法
get_the_archive_titlethe_archive_titleis_post_type_archiveget_post_type_archive_linkget_post_type_archive_template
引入
3.1.0
棄用
-

post_type_archive_title是一個WordPress函式,用於生成一個文章型別的存檔頁的標題。它接受一個引數:$post_type(文章型別物件或名稱),並以字串形式返回存檔標題。

顯示或檢索文章型別存檔的標題。

這是對 archive.php 和 archive-{$post_type}.php 模板檔案的優化,用於顯示文章型別的標題。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function post_type_archive_title( $prefix = '', $display = true ) {
if ( ! is_post_type_archive() ) {
return;
}
$post_type = get_query_var( 'post_type' );
if ( is_array( $post_type ) ) {
$post_type = reset( $post_type );
}
$post_type_obj = get_post_type_object( $post_type );
/**
* Filters the post type archive title.
*
* @since 3.1.0
*
* @param string $post_type_name Post type 'name' label.
* @param string $post_type Post type.
*/
$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
if ( $display ) {
echo $prefix . $title;
} else {
return $prefix . $title;
}
}
function post_type_archive_title( $prefix = '', $display = true ) { if ( ! is_post_type_archive() ) { return; } $post_type = get_query_var( 'post_type' ); if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); } $post_type_obj = get_post_type_object( $post_type ); /** * Filters the post type archive title. * * @since 3.1.0 * * @param string $post_type_name Post type 'name' label. * @param string $post_type Post type. */ $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type ); if ( $display ) { echo $prefix . $title; } else { return $prefix . $title; } }
function post_type_archive_title( $prefix = '', $display = true ) {
	if ( ! is_post_type_archive() ) {
		return;
	}

	$post_type = get_query_var( 'post_type' );
	if ( is_array( $post_type ) ) {
		$post_type = reset( $post_type );
	}

	$post_type_obj = get_post_type_object( $post_type );

	/**
	 * Filters the post type archive title.
	 *
	 * @since 3.1.0
	 *
	 * @param string $post_type_name Post type 'name' label.
	 * @param string $post_type      Post type.
	 */
	$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );

	if ( $display ) {
		echo $prefix . $title;
	} else {
		return $prefix . $title;
	}
}

常見問題

FAQs
檢視更多 >