Alphabetical Sorting of Categories
-
Okay, so I was adding a new category “Photoblography” to my WordPress installation… and much to my dismay, it was displayed LAST in the category listing with no front-end way to make it appear under “Personal”… where it belongs… with the “P’s”.
So that means getting under the hood. Oh joy.
After 15 minutes of digging around, I found the bug (in my mind anyway) and fixed it. If you want your categories to display properly in alphabetical order and NOT in order of when you added it, then do this REALLY REALLY simple fix to the following file: template-functions-category.php which can be found in /wordpress/wp-includes/
Around like 290 or so, you’ll see these lines of code:
$query = "
SELECT cat_ID, cat_name, category_nicename, category_description, category_parent
FROM $tablecategories
WHERE cat_ID > 0 $exclusions
ORDER BY $sort_column $sort_order";
* please note that “category_description, category_parent” should be on the same line as its previous line. Because of the size of this column, it wraps around.
On the last line, remove$sort_column $sort_order
and replace it withcat_name
. That line should look like this:
ORDER BY cat_name";
And whallah, your categories will display as they ought to… alphabetically.
If you’re concerned about getting rid of the code permanently, simply do a little commenting out and rearranging so your code looks like this:
$query = "
SELECT cat_ID, cat_name, category_nicename, category_description, category_parent
FROM $tablecategories
WHERE cat_ID > 0 $exclusions
ORDER BY cat_name";
### hack by michael -- original below
//ORDER BY $sort_column $sort_order";
Enjoy!
- The topic ‘Alphabetical Sorting of Categories’ is closed to new replies.