WordPress.org

Support

Support » How-To and Troubleshooting » How to alphebetize `the_category`?

How to alphebetize `the_category`?

  • When listing categories on an individual entry, they always get displayed in the order I created the categories (by category ID). I know list_cats has a sort_order argument, but is there any way to alphabetize the_category?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I tried searching for the answer to this, but came up with nothing. I would also like to know how to alphabetize the_category.

    Interesting method used here was to change the Primary Index on the wp_categories table:
    http://wordpress.org/support/topic/13079#post-116040

    This feature to sort the_category by name has been requested in Trac:
    http://trac.wordpress.org/ticket/1302

    This seems to work in 1.5.2 and will even cause the Manage->Posts screen to show each Post’s categories sorted alphabetically by the category-nicename field.

    In wp-content/template-functions-category.php in the get_the_category functions at line 15 you should see sort($categories)

    change that line to:

    usort($categories, create_function('$a,$b','return strcasecmp($a[2],$b[2]);'));

    Of course, remember to backup the wp-content/template-functions-category.php file before making this change just in case it doesn’t work for you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to alphebetize `the_category`?’ is closed to new replies.