WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Hide a category in the sidebar

[Resolved] Hide a category in the sidebar

  • I read on http://codex.wordpress.org/Template_Tags/wp_list_cats that the function call wp_list_cats() can be used to hide specified categories.

    Yet, when I use the following call, only the second category is hidden, leaving the first (the ‘Uncategorized’ category) still showing on the side bar.

    wp_list_cats('sort_column=name&exclude="1, 2"');

    Now, when I don’t enclose the category IDs using double quotes (see example below), I get an error saying that the function call foreach() in template-functions-category.php received an invalid argument.

    wp_list_cats('sort_column=name&exclude=1, 2');

    Any reason why?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I figured out the problem.

    The proper syntax is indeed without the double quotes, as in:

    wp_list_cats('sort_column=name&exclude=1, 2');

    However, if the exclude rule results in no categories being shown, no argument is passed to the foreach() call and therefore, it generates an error when that line interpreted (line 321 in <root>/wp-includes/template-functions-category.php).

    My suggestion is to add a note to the documentation stating this potential error.

    However, if the exclude rule results in no categories being shown

    Well, if that’s the result – it means you don’t want to show any categories. Then why not just delete the template tag from the sidebar…?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Hide a category in the sidebar’ is closed to new replies.
Skip to toolbar