The MU forums have moved to WordPress.org

Sort category lists alphabetically? (5 posts)

  1. thelaw
    Member
    Posted 15 years ago #

    This is a great page that tells you all the wp_list_cats parameters.

    http://codex.wordpress.org/Template_Tags/wp_list_cats

    What is sorely missing is sorting alphabetically. While I have great looking output of my categories I'm wondering how you could prefer "ascending order" to be by ID and leave out alphabetical!!!! For the most part I would think a built in "sort asc" would be built in as part of the mysql command that could have been referenced here.

    What I'm doing is placing this code (underlines added)

    <___? php wp_list_cats('sort_column=id&optioncount=0&hide_empty=0@&use_desc_for_title=0'); ?__>

    into the sidebar and spitting out beautiful looking categories. Unfortunately, it's not spitting them out alphabetically and I don't see a parameter to call to do so!

  2. grandslambert
    Member
    Posted 15 years ago #

    You may want to change the 'sort_column' to name instead of ID. It lists this option under the "Parameters" section on the page you specified. 'id' is the default, as is 'asc' for sort order. So change id to name in the sort_column and you are golden!

  3. thelaw
    Member
    Posted 15 years ago #

    Dude... YOU are golden! Muchas gracias!!!! It looks great!!!!

    After looking at the page again I see the "values" parameters and just didn't see any examples with them. Great!!!

  4. grandslambert
    Member
    Posted 15 years ago #

    BTW, you should also know that the "list_cats()" function has been deprecated and will eventually stop working in a future version. You should update your application to use the "wp_list_categories()" as desecribed here:

    http://codex.wordpress.org/Template_Tags/wp_list_categories

    This new function, by default, lists the categories by name in ascending order, which of course is what you want. :)

  5. thelaw
    Member
    Posted 15 years ago #

    MANY thanks for this tip too! I'm glad to know that my sidebar info won't magically disappear someday. :) Made a few modifications with the parameters and works like a charm...

About this Topic