[英]WordPress Widget Categories hook
I see there is a get_the_categories hook. 我看到有一个get_the_categories钩子。 This doesn't seem to effect the categories output by the default WP categories widget.
这似乎不会影响默认WP Categories窗口小部件输出的类别。
function wp_cat_filter($categories) {
var_dump($categories); // I'd like to remove a category before it's output.
}
add_filter('get_the_categories','wpr_cat_filter');
This works great and I have an I have an object to work with here but not when it comes to the widget? 这很好用,我有一个可以在这里使用的对象,但是关于小部件却没有? I'm looking to remove a category here.
我想在这里删除类别。
Is there a hook for the widget categories specifically and wouldn't that call the get_categories function? 是否有专门针对窗口小部件类别的钩子,难道没有调用get_categories函数吗?
I think you should be able to use the widget_categories_args
filter: 我认为您应该可以使用
widget_categories_args
过滤器:
This filter is used by the default WordPress Widget: Categories before it passes arguments to the wp_list_categories() function.
默认的WordPress Widget:类别使用此过滤器,然后将参数传递给wp_list_categories()函数。
For example, something like this might work: 例如,类似这样的方法可能会起作用:
function wpr_cat_filter($args) {
// remove category 1, 2 and 3
$exclude = array(1, 2, 3);
if (isset($args['exclude'] ) && !empty($args['exclude'])) {
$exclude = array_unique(array_merge(explode(',', $args['exclude']), $exclude));
}
$args['exclude'] = implode(',', $exclude);
return $args;
}
add_filter('widget_categories_args', 'wpr_cat_filter');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.