• I have been trying to figure it out forever. I made it WAY more complicated then I needed to. SO if anyone wants to display the children of just ONE category, here is a way to do it. This will obviously be a list.

    Maybe I’ll write it as a plug-in when I have time. Like next year!

    <ul>
    <?php

    $get_children = $wpdb->get_results('SELECT * FROM dj_categories WHERE category_parent = "THE cat_ID of the PARENT that you want"');

    foreach ($get_children as $child) {
    echo '<li><a href="./?cat='.$child->cat_ID.'" title="View all posts filed under '.$child->cat_name.'">'.$child->cat_name.'</a></li>';
    }

    ?>
    </ul>

Viewing 6 replies - 1 through 6 (of 6 total)
  • can you clarify “dj_categories”?

    Where exactly do you implement this?

    Thread Starter dave_merwin

    (@dave_merwin)

    Oops Sorry. Try this…

    <ul>
    <?php
    $get_children = $wpdb->get_results('SELECT * FROM your category table WHERE category_parent = "The cat_ID of the parent that you want"');
    foreach ($get_children as $child) {
    echo '<li><a href="./?cat='.$child->cat_ID.'" title="View all posts filed under '.$child->cat_name.'">'.$child->cat_name.'</a></li>';
    }
    ?>
    </ul>

    I used it as a side bar to display the children of a parent category. It generates a list of the children of the parent.

    Wow, this is just what I was looking for. Is there a way a sort the list of child categories, by alphabetical order for example?

    Is there a way a sort the list of child categories, by alphabetical order for example?

    Change the query to:

    $get_children = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE category_parent = 'The cat_ID of the parent that you want' ORDER BY cat_name ASC");

    Thanks, Kafkaesqui, that works perfectly.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying the category children of ONE category’ is closed to new replies.