get_the_archive_description()
云策文档标注
概述
get_the_archive_description() 函数用于检索作者、文章类型或分类法术语存档的描述。它根据当前查询类型调用相应的函数获取描述,并应用过滤器以允许自定义。
关键要点
- 函数返回字符串类型的存档描述。
- 根据查询类型(作者、文章类型存档或其他)调用不同函数:is_author() 时使用 get_the_author_meta('description'),is_post_type_archive() 时使用 get_the_post_type_description(),否则使用 term_description()。
- 提供 apply_filters('get_the_archive_description', $description) 钩子,允许开发者过滤描述内容。
- 相关函数包括 the_archive_description() 用于显示描述,以及多个查询和模板函数如 is_author()、is_post_type_archive() 等。
- 自 WordPress 4.1.0 引入,4.7.0 添加作者存档支持,4.9.0 添加文章类型存档支持。
代码示例
function get_the_archive_description() {
if ( is_author() ) {
$description = get_the_author_meta( 'description' );
} elseif ( is_post_type_archive() ) {
$description = get_the_post_type_description();
} else {
$description = term_description();
}
/**
* Filters the archive description.
*
* @since 4.1.0
*
* @param string $description Archive description to be displayed.
*/
return apply_filters( 'get_the_archive_description', $description );
}
原文内容
Retrieves the description for an author, post type, or term archive.
Description
See also
Source
function get_the_archive_description() {
if ( is_author() ) {
$description = get_the_author_meta( 'description' );
} elseif ( is_post_type_archive() ) {
$description = get_the_post_type_description();
} else {
$description = term_description();
}
/**
* Filters the archive description.
*
* @since 4.1.0
*
* @param string $description Archive description to be displayed.
*/
return apply_filters( 'get_the_archive_description', $description );
}
Hooks
- apply_filters( ‘get_the_archive_description’, string $description )
-
Filters the archive description.