post_type_archive_title()
post_type_archive_title( string $prefix = ”, bool $disp…
post_type_archive_title( string $prefix = ”, bool $display = true )
显示或检索文章类型存档的标题。
Display or retrieve title for a post type archive.
显示或检索文章类型存档的标题。
Display or retrieve title for a post type archive.
目录锚点:#说明#参数#返回#源码#笔记
说明(Description)
这是为存档.php以及存档-{$post_type}.php模板文件,用于显示post类型的标题。
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $prefix | (string) | 可选 | 标题前要显示的内容。 |
| $display | (bool) | 可选 | 是显示还是检索标题。 |
返回(Return)
(string|void)检索时的标题,显示时为空或失败。
源码(Source)
/**
* Display or retrieve title for a post type archive.
*
* This is optimized for archive.php and archive-{$post_type}.php template files
* for displaying the title of the post type.
*
* @since 3.1.0
*
* @param string $prefix Optional. What to display before the title.
* @param bool $display Optional, default is true. Whether to display or retrieve title.
* @return string|void Title when retrieving, null when displaying or failure.
*/
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 );
/**
* Filter 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;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 3.1.0 | wp-includes/general-template.php:1366 | 3 | 5 |
笔记(Notes)
显示自定义文章类型标题:
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!