WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to show empty categories on the default category widget (8 posts)

  1. Info Man
    Member
    Posted 2 years ago #

    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));
    ?>

  2. 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.

  3. Info Man
    Member
    Posted 2 years ago #

    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

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    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

  5. 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

  6. Info Man
    Member
    Posted 2 years ago #

    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

  7. Info Man
    Member
    Posted 2 years ago #

    love your quick response

  8. Myself, I thank alchymyth. He's the more productive reply one. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.