Support » Installing WordPress » Categories Not Alphabetizing and Showing Subcategories in 1.5

  • I probably need to be spanked on my overuse of categories and my using wordpress for a CMS. But I’m having problems in 1.5 with my categories sorting and showing subcategories.

    I used Kubrick for 1.2 and they worked fine with this code:

    <h2><?php _e(‘Categories’); ?></h2>

      <?php list_cats(0, ”, ‘name’, ‘asc’, ”, 1, 0, 1, 1, 1, 1, 0,”,”,”,”,”) ?>

    I see the same code in the sidebar.php but it’s not behaving the same way.

    Here’s a section of my site that works properly with Kubrick and 1.2:

    Here’s the upgraded section with 1.5 with categories not working:

Viewing 15 replies - 1 through 15 (of 15 total)
  • Did you check in the Codex whether they changed something?

    Moderator James Huff


    Volunteer Moderator

    Have a read through this (it’s a good starting point and will at least get the categories organized by name)):

    Thread Starter americasroof


    Wow! Thanks macmanx for once again solving the problem amazingly quickly by simply
    <?php wp_list_cats(‘sort_column=name& hide_empty=0’); ?>
    Instead of:
    <?php list_cats(0, ”, ‘name’, ‘asc’, ”, 1, 0, 1, 1, 1, 1, 0,”,”,”,”,”) ?>

    Now to look a gift horse in the mouth — if I could only get the number of posts in each category as was done earlier.

    OOh!! This solves a problem I’ve been having with list_cats!! And I’m with you. I’d like the number of posts per cat.

    Thread Starter americasroof


    After looking at the wiki I see you can change the options

    I got the number of posts back with the following code:
    <?php wp_list_cats(‘sort_column=name& hide_empty=0& optioncount=1’); ?>

    However in this case it is listing categories with 0 posts but we’re getting there.

    <?php wp_list_cats(‘sort_column=name& hide_empty=0& optioncount=1’); ?>

    works fine. But with ‘hide_empty=1’, I get the same problem(showing subcategories). Does anyone have a solution to this issue? Thanks.

    Yes, I just tracked down and fixed the problem in my WP 1.5 installation. In “function list_cats” in wp-includes/template-functions-category.php, the query that’s run if hide_empty=0 does use the sort_column and sort_order values you specify. But the query that’s run if hide_empty=1 does not use the values you specify.

    Look for the assignment to $cat_counts on line 292. On the line before it, add:

    $sort_column = 'cat_'.$sort_column;

    Then, at the end of SQL query, add:

    ORDER BY $sort_column $sort_order

    Then you’re good to go!

    Yes! Finally I got my darn Cat List to be in alphabetical order! Woot!

    Maybe the revised template-functions-category.php file would solve this problem

    Oh no. I might need a little (more) hand holding. I would also like the subcategories indented.

    In sidebar.php I changed:
    <?php list_cats(0, ”, ‘name’, ‘asc’, ”, 1, 0, 1, 1, 1, 1, 0,”,”,”,”,”) ?>
    <?php wp_list_cats(‘sort_column=name& hide_empty=0’); ?>

    but the subcategories are still flush. Did I miss an earlier step?


    <<<<Hey stupid–check your ftp settings. >>>
    Sorry for the wasted bandwidth–that worked just as it should have.

    @mikett: Thanks for your solution. But there is a little mistake: if you switch back to hide_empty=0, there are some errors. I fixed it: add this code on line before 292:

    if ($hide_empty) {
    $sort_column = ‘cat_’.$sort_column;
    $order_exp = “ORDER BY $sort_column $sort_order”;

    At the end of the SQL-Query, add $order_exp. The line (after adding the code above) 303:

    GROUP BY category_id $order_exp”);

    This solution works with hide_empty=0 and hide_empty=1.

    But one problem is still unsolved: the indent of the subcategories is missing if hide_empty=1. The indent of all items is identical.

    So I have a working solution for the last problem (indent with hide_empty=1) as well.

    on line 274, adding category_parent:
    $extra_fields = 'cat_name, category_nicename, category_description, category_parent,';

    befor line 315, add this code:
    else if (!count($categories) && $hide_empty) {
    $query = "
    SELECT cat_ID, cat_name, category_nicename, category_description, category_parent
    FROM $wpdb->categories
    WHERE cat_ID > 0 $exclusions
    ORDER BY $sort_column $sort_order";
    $categories = $wpdb->get_results($query);

    I can’t explain exactly what the problem was. I only thought that we have to fill the $categories variable somewhere if we are on a recursive way. Since the problem was that the variable $category_posts was only filled on the first loop (on the recursive it was empty, problem causes in line 290 -> false). I don’ t know the sense/task of $category_posts.

    So this solution works. But I don’t know it’s the right way to solve this problem.

    Thanks for this bit of code:

    <?php wp_list_cats('sort_column=name& hide_empty=0'); ?>

    Works well.

    thanks this is a great script, however I would like the menu to be ordered as configured in the Administraton pannel of wordpress i.e. by the “page_order” setting.

    I thought that I could do this by changing the code to

    <div id=”pages_nav”>
    if(function_exists(“wp_pages_nav”)) {

    doesn’t seem to work for me… any ideas ?

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Categories Not Alphabetizing and Showing Subcategories in 1.5’ is closed to new replies.