WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_categories - Show empty cats but as plain text. (9 posts)

  1. DLubofsky
    Member
    Posted 1 year ago #

    Need all categories listed, but only non-empty categories need to be links:

    Apples (3)
    Carrots (2)
    Melons (0)
    Tomatos (7)

    Can not seem to figure out how to accomplish this. Thanks for any assistance!
    David

  2. Andrew Bartel
    Member
    Posted 1 year ago #

    Why not just pass hide_empty => 1 in your arguments to wp_list_categories()? Is it really necessary to display a category that doesn't have anything in it?

    If so, I'd say you'd probably need to finangle the css and disable the link with jquery.

  3. DLubofsky
    Member
    Posted 1 year ago #

    It is necessary. Displaying a client list, and though we do not currently have work posted under some clients, we want to recognize them.

    Currently, we are manually adding css to change style, and js to disable link, each time we add a client. But, trying to make it less manual--has to be a less 'hacky' way of doing it.

  4. DLubofsky
    Member
    Posted 1 year ago #

    Sounds pretty limiting to think it has to be done manually every time a client is added. Figured there had to be a better way.

  5. Andrew Bartel
    Member
    Posted 1 year ago #

    Ok, can you throw up a link to the site and I'll take a look at the list?

    You could probably do some kind of conditional selector with js.

  6. DLubofsky
    Member
    Posted 1 year ago #

    Working on this locally--it is a new version of out site. I will get it online this afternoon behind the scenes so you can take a peak. Thanks for taking the time to look at it--very generous of you. Will get you link shortly.

  7. vjpo
    Member
    Posted 1 year ago #

    It is easy to do with get_categories() function and also possible by filtering wp_list_categories() html output through add_filter( 'wp_list_categories', 'custom_filter_function' ), but I can't figure out now how to make it trough add_filter().

  8. Andrew Bartel
    Member
    Posted 1 year ago #

    I suppose you could do it with get_categories() but wouldn't you end having to write a recursive function? That's not particularly simple.

    I'll be interested to see if there's something unique about empty categories in the css or if it can be targeted specifically with jquery.

  9. vjpo
    Member
    Posted 1 year ago #

    It is really easier with get_categories(). By default wp_list_categories() does not provide special classes for empty categories. JQuery can catch the link by (0) text, but, again, easier to use get_categories().

Topic Closed

This topic has been closed to new replies.

About this Topic