• how can I prevent the message “No categories” from showing on wp_list_categories?
    I’d like nothing to display instead of a message saying there’s nothing to display.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter csleh

    (@csleh)

    any ideas? It’s really disrupting.

    Delete the template tag from the template or use the echo=0 command to return the result to a variable then if the there are categories display them.

    Thread Starter csleh

    (@csleh)

    Unfortunately I can’t delete it from the template, since there are a lot of categories on the site.

    I tried adding echo=0 like this:
    orderby=id&show_count=0&echo=0&exclude=4,6,20

    but it didn’t have any effect. “No categories” still displays.

    Unfortunately I can’t delete it from the template, since there are a lot of categories on the site.

    That is ironic in light of the fact you are returning “No categories”.

    Oh well, this is what I meant:

    <?php
    $cats = wp_list_categories('title_li&orderby=id&show_count=0&echo=0&exclude=4,6,20');
    if (!strpos($cats,'No categories') ){
    echo $cats;  // or wp_list_categories('orderby=id&show_count=0&echo=1&exclude=4,6,20');
    }
    ?>

    Thread Starter csleh

    (@csleh)

    Thank you.

    I see what I typed does sound funny. There is only one area with lots of levels of categories and more might come. So I am trying to get navigation that will work with whatever levels of categories a particular area has.

    this is actually a really super huge pain.

    my additional problem is that I found a way to display the subcategories that works and doesn’t break the site. It is not ideal, because when on a post only the great-grandparent categories show in the sidebar. But I’m no longer tearing my hair out on that.

    I have tried plugins but they screwed up my site (like no one could see Pages anymore)

    so this is what I’m using, but I can’t combine the example with it. If you could help me out I would REALLY appreciate it. I get this is all volunteer though.

    <?php
    if (is_category()) {
    $this_category = get_category($cat);
    }
    ?>
    <?php
    if($this_category->category_parent)
    $this_category = wp_list_categories('orderby=id&show_count=0&echo=0&exclude=4,6,20&title_li=&depth=2&use_desc_for_title=1&child_of='.$this_category->category_parent."&echo=0"); else
    $this_category = wp_list_categories('orderby=id&show_count=0&echo=0&exclude=4,6,20&title_li=&depth=1&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
    if ($this_category) { ?>
    <ul class="leftnav">
    <?php echo $this_category; ?>
    </ul>
    <?php } ?>

    https://www44.a2hosting.com/~traffic1/safety

    Thread Starter csleh

    (@csleh)

    Urgh. Upgraded to 2.8, tried about 6 navigation plugins, tried a tutorial on grabbing the grandparent from page id, like that. Nothing works so I’m back to the above code.

    There are only 2 issues:
    – doesn’t show parent category on a post, only grandparents. I can live with this

    – shows “no categories” in an area that isn’t as deep as the other areas

    I’d like to either get rid of the message OR conditionally hide the category listing in the one slim area.

    I’m going to change to a page for that slim area for now, until it expands to more categories. Still seems funny this functionality isn’t built into wordpress yet. someday!

    I am having the exact same problem and was using the exact same code. Did you ever find a solution? Because I am pulling my hair out over it now!

    I have “no categories” showing up in my nav menu…any way to get rid of it!

    Anonymous User 260705

    (@anonymized-260705)

    I’m having exactly the same problem with 2.9.1. Any ideas?

    Thank you!

    Yep, me too.

    New Install of 2.9.2. Selected to make the default uncategorized category excluded from the Menu. (Entered the ID of the uncategorized category to exclude form the category menu (e.g. 2,13,45).)

    The Top Nav now has “No categories” listed.

    Arg.

    How do I add a Category / Post to the text NO CATEGORIES on the navi?

    I solved it with a css trick.
    Assuming that we are listing links and the “No categories” message is not a link and assuming that the css class of the UL is .cat_menu

    ul.cat_menu li {text-indent:-99999px;}
    ul.cat_menu li a, ul.cat_menu li a:visited {text-indent:0px;}

    The results is that non links will not show up

    Just in case anyone is still looking for a solution to this, there is a simple small addition to your functions file that works perfectly here:

    https://www.category-icons.com/2009/07/how-to-hide-no-categories-if-there-are-no-subcategories/

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘get rid of “no categories” message’ is closed to new replies.