钩子文档

the_category_list

💡 云策文档标注

概述

the_category_list 是一个 WordPress 过滤器钩子,用于在构建分类列表前过滤分类数据。它允许开发者修改与特定文章关联的分类数组。

关键要点

  • 过滤器钩子名称:the_category_list
  • 参数:$categories(WP_Term[] 数组,文章的分类)和 $post_id(int|false,文章 ID,false 时默认为循环中的当前文章)
  • 用途:在 get_the_category_list() 函数中调用,用于自定义分类列表的生成
  • 相关函数:get_the_category_list(),位于 wp-includes/category-template.php
  • 版本历史:从 WordPress 4.4.0 版本引入

📄 原文内容

Filters the categories before building the category list.

Parameters

$categoriesWP_Term[]
An array of the post’s categories.
$post_idint|false
ID of the post to retrieve categories for.
When false, defaults to the current post in the loop.

Source

$categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id );

Changelog

Version Description
4.4.0 Introduced.