WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Hide a category in the sidebar (3 posts)

  1. transweb
    Member
    Posted 8 years ago #

    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?

  2. transweb
    Member
    Posted 8 years ago #

    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.

  3. moshu
    Member
    Posted 8 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags