0

Is there a way I can display all categories in the categories widget that comes with wordpress. I do not want to have to edit the core files and I want to stay away from rewriting the widget, but if need be I will. Is there anyway to hook into the widget just to get this functionality.

2

Not sure what you mean by 'display all categories', i thought it does that by default?

Anyways...you can hook into it, using the following filter hooks:

  • widget_categories_args
  • widget_categories_dropdown_args

Both hooks pass the query args to get the categories as an array.

The default is array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h), wherein $c and $h are booleans and represent if the user selected 'Show post counts' and 'Show hierarchy' in the widget's options, respectively.

The dropdown version gets another value: $cat_args['show_option_none'] = __('Select Category');, setting the label for the 'none selected' state.

You'll can hook the same callback to both filters, so that the result is the same no matter if Show as dropdown is selected or not.

BTW: The widgets that come with WP out of the box are defined in wp-includes/default-widgets.php, the code in there is quite readable.

2

simple answer:

add_filter( 'widget_categories_args', 'mytheme_widget_cat_args' );
function mytheme_widget_cat_args($cat_args) {
    // the default for "hide_empty" = 1, so
    $cat_args['hide_empty'] = 0;
    // we can override any other defaults here too
    return $cat_args;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.