the_category
云策文档标注
概述
the_category 是一个 WordPress 过滤器,用于修改当前文章的分类或分类列表的输出。它允许开发者自定义分类列表的显示方式,例如替换文本或调整格式。
关键要点
- 过滤器名称:the_category,用于过滤分类列表。
- 参数:$thelist(分类列表字符串)、$separator(分隔符)、$parents(父分类显示方式,可选 'multiple'、'single' 或空)。
- 应用场景:常用于主题或插件开发中,通过 add_filter 钩子自定义分类输出。
代码示例
function wpdocs_category_filter( $categories ) {
return str_replace( 'Tools', 'All tools', $categories );
}
add_filter( 'the_category', 'wpdocs_category_filter' );
原文内容
Filters the category or list of categories.
Parameters
$theliststring-
List of categories for the current post.
$separatorstring-
Separator used between the categories.
$parentsstring-
How to display the category parents. Accepts
'multiple','single', or empty.
Source
return apply_filters( 'the_category', $thelist, $separator, $parents );
Changelog
| Version | Description |
|---|---|
| 1.2.0 | Introduced. |
Skip to note 2 content
Hyppolite T.
Filter the list of categories to simply do a text replacement and return the result.
function wpdocs_category_filter( $categories ) { return str_replace( 'Tools', 'All tools', $categories ); } add_filter( 'the_category', 'wpdocs_category_filter' );