WP and Category Lists


< ?php wp_list_cats('optioncount=1&children=0&sort_column=name'); ?>

I found that by accident. I had been using:

< ?php wp_list_cats('optioncount=1&children=true&hide_empty=1'); ?>

or

< ?php wp_list_cats('optioncount=1&children=false&hide_empty=0'); ?>

and the reverse of both, flip-flopped, if you will.

I was using the WIKI for WP, looking at the tags and what was what.
This attribute: CHILDREN is for top categories to SHOW them or NOT to , use of this is TRUE or FALSE …

  • I was able to get EVERY category and subcategory to show, whether they had entries or not
    or
  • I was able to get Top Categories which had entries only, and their subcategories showed up in this case, but if a sub-category belonged to an empty Top category, it’d not show up.

So I took out the “children” string and fooled around with the tags more, and still had nothing that I wanted. So then I added in a new attribute for example (exclude category with that ID number from the list),
and off-handedly decided to put the “children” thing back into the tag, and I, without thinking, hit “0” (zero).
children=0.

I saved the template, reloaded the index.php and voila! Something different! A list of every category that had something in it, in a straight line, a no-sub look, and then I realized why, it was the
children=0.

Mistakes often bring about the greatest inventions! This is no invention, maybe it’s something that is known, but it was unknown to me and I surely liked the result. So I added the “sort by name” attribute and the list is now alphabetized. There it graces the sidebar, guaranteed to be there for at least one day, maybe longer, but not forever, for surely I’ll change it again. It’s safe as this for tonight though 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *