• Hi all,

    Does anyone out there know how to get the dropdown_cats function to show the category hierarchy? Can it be done?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Don’t remember ever seeing it. Which doesn’t mean it’s impossible…

    The trick is that an HTML select list is, by nature, pretty one-dimensional. So you have to insert dashes or spaces to make it look hierarchical (if I spelled that right I want a cookie).
    So your drop down list actually has stuff like:

    CatA
    - SubCat1
    - SubCat2
    -- SubCata
    --- subcatii
    CatB
    - SubCat 3

    Ok, that look isn’t a big deal. But then you have to “decode” it on the form post side to actually figure out that ” — SubCatB” is a real category. By decode, in this case I guess I mean strip leading whitespace and dashes.

    Impossible? Not at all. And look, verbose pseudo-code!

    Thread Starter benkeen

    (@benkeen)

    Hi HandySolo et al.

    I hope this isn’t bad form, but I went and modified the dropdown_cats code to re-sort the select options to indicate hierarchy as we discussed above. For a rather poor example (only one level of category nesting) see:

    https://www.benjaminkeen.com/

    The code is pretty clean & efficient, builds on the existing code and is backward compatible (defaulting to no nesting). I added two new parameters to allow users to indicate they want to show the hierarchy and specify their choice of nesting mark (defaulting to — – a dash! – like in the WordPress UI).

    I’m not sure what the process is, but I can post the code here, on my website or send it to you guys if need be…

    Awesome script. Thanks guys!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to show category hierarchy with dropdown_cats’ is closed to new replies.