Support » Fixing WordPress » How to show empty categories on the default category widget

  • Resolved Info Man

    (@iwanuswak)


    edit:

    wp-includes/default-widgets.php

    change this:
    <?php
    $cat_args[‘title_li’] = ”;
    wp_list_categories(apply_filters(‘widget_categories_args’, $cat_args));
    ?>

    to this:
    <?php
    $cat_args[‘title_li’] = ”;
    $cat_args[‘hide_empty’] = 0;
    wp_list_categories(apply_filters(‘widget_categories_args’, $cat_args));
    ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Brute Squad and Volunteer Moderator

    No, do NOT do that. EVER.

    Editing any core file will cause you massive debilitating pain and suffering. If you need to modify something like that, use a filter, add an action, or just write your own function.

    Info Man

    (@iwanuswak)

    how to do it then in a simple, efficient and secure way?

    maybe the wordpress folks should ad this as an option in the default widget? show/hide empty categories.

    I really need this

    Michael

    (@alchymyth)

    do not edit WordPress core templates.

    see this last line:
    apply_filters('widget_categories_args', $cat_args

    this points to the possibility to use a filter function to change the parameters;

    example code, to add to functions.php of the used theme:

    add_filter('widget_categories_args','show_empty_categories_links');
    function show_empty_categories_links($args) {
    	$args['hide_empty'] = 0;
    	return $args;
    }

    http://codex.wordpress.org/Template_Tags/wp_list_categories

    Moderator Jan Dembowski

    (@jdembowski)

    Brute Squad and Volunteer Moderator

    There are many plugins that provide category widgets. Rather than editing a core file, experiment with one of them.

    They may be able to provide the functionality you are looking for.

    http://wordpress.org/extend/plugins/search.php?q=category+widget

    Info Man

    (@iwanuswak)

    thank you guys. i’ve undone the core template edits and added the code from alchymyth to the P2 themes functions.php (at the end).

    Works fine for me

    Info Man

    (@iwanuswak)

    love your quick response

    Moderator Jan Dembowski

    (@jdembowski)

    Brute Squad and Volunteer Moderator

    Myself, I thank alchymyth. He’s the more productive reply one. 😉

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to show empty categories on the default category widget’ is closed to new replies.