dave_merwin
Member
Posted 7 years ago #
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>
can you clarify "dj_categories"?
Grievance
Member
Posted 7 years ago #
Where exactly do you implement this?
dave_merwin
Member
Posted 7 years ago #
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.
Bricolou
Member
Posted 7 years ago #
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");
Bricolou
Member
Posted 7 years ago #
Thanks, Kafkaesqui, that works perfectly.