WordPress.org

Ready to get started?Download WordPress

Forums

force wp_list_categories NOT to show No catergories (4 posts)

  1. jrodgers
    Member
    Posted 6 years ago #

    I have a custom category list in my side bar
    wp_list_categories('child_of=51&hide_empty=1&title_li=&')

    as there are no sub categories to category 51 it return 'No categories', what i want is for it to show nothing if there are no active child categories, and i would rather not alter the actual function

  2. sophiavancouver
    Member
    Posted 6 years ago #

    Yes, I'm looking for the same thing too. I'm sure there must be a file somewhere that contains the 'no categories' text that is called when no categories show up, and I've been looking for it to delete that comment. Any pointers from anyone on where that is located? There doesn't seem to be anything in the usage for wp_list_categories that allows me to turn the error message 'no categories' off.

  3. jrodgers
    Member
    Posted 6 years ago #

    what i ended up doing was running the category call with no echo, checking if the return was No Categories and outputting based on that...

    if(wp_list_categories('child_of=51&hide_empty=1&title_li=&echo=0') != 'No Categories'){
    wp_list_categories('child_of=51&hide_empty=1&title_li=&echo=1')

    }

  4. WPQuestions
    Member
    Posted 5 years ago #

    Good solution jrodgers. In my implementation I had to check if wp_list_categories was equal to "
    <li>No Categories</li>
    "

Topic Closed

This topic has been closed to new replies.

About this Topic