widget_comments_args
云策文档标注
概述
widget_comments_args 是一个 WordPress 过滤器,用于修改“最近评论”小工具的参数。它允许开发者自定义查询评论的条件,例如评论数量、状态和关联文章状态。
关键要点
- 这是一个过滤器钩子,用于调整 WP_Widget_Recent_Comments 小工具的查询参数。
- 接受两个参数:$comment_args(评论查询参数数组)和 $instance(当前小工具设置数组)。
- 默认参数包括 'number'(评论数量)、'status'(评论状态为 'approve')和 'post_status'(文章状态为 'publish')。
- 从 WordPress 4.9.0 版本开始添加了 $instance 参数,3.4.0 版本引入此过滤器。
- 相关函数:WP_Widget_Recent_Comments::widget() 用于输出小工具内容。
代码示例
apply_filters(
'widget_comments_args',
array(
'number' => $number,
'status' => 'approve',
'post_status' => 'publish',
),
$instance
)
原文内容
Filters the arguments for the Recent Comments widget.
Description
See also
- WP_Comment_Query::query(): for information on accepted arguments.
Parameters
$comment_argsarray-
An array of arguments used to retrieve the recent comments.
$instancearray-
Array of settings for the current widget.
Source
apply_filters(
'widget_comments_args',
array(
'number' => $number,
'status' => 'approve',
'post_status' => 'publish',
),
$instance
)