显示或检索帖子类型存档的标题。
原型
post_type_archive_title( string $prefix = '', bool $display = true )
描述
这是针对archive.php和archive – {$ post_type} .php模板文件进行优化的,用于显示帖子类型的标题。
参数
$prefix
(string)
(Optional)
标题前显示的内容。
$display
(bool)
(Optional)
是否显示或检索标题。
返回值
(string|void)
检索时的标题,显示或失败时为null。
源文件
路径:wp-includes/general-template.php
<?php
...
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;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/post_type_archive_title/