shaungraham
Member
Posted 4 years ago #
Is there a way to restrict the categories that show up in a category list ?
I have a list of categories in my side bar and would like to exclude all categories that are a child of other categories.
Is this possible ? And if so could you point me in the right direction.
Thanks
I thought the template tag, wp_list_categories(), would do it, but it doesn't have a depth parameter so something like this:
<?php
$parent_cats = $wpdb->get_results("SELECT *
FROM $wpdb->term_taxonomy
WHERE taxonomy = 'category' AND parent = 0");
foreach ($parent_cats as $parent) {
$cat_name = get_the_category_by_ID($parent->term_id);
echo '<a href="' . get_category_link($parent->term_id) . '" title="' . sprintf(__("View all posts in %s"), $cat_name) . '">' . $cat_name . '</a>
';
}
?>
jwesseldyke
Member
Posted 4 years ago #
I have tried every widget and suggestion known to man to get my categories to display the way I want them... Now I found this, and it looks like you've got the goods here... Only question is... Where does it go?
I've tried a hack for wp_list_categories which I'm sure would work... But I must be doing it wrong... I found it here... I also tried a css "trick" the same person mentioned but again, must have done something wrong... They suggested editing style.css to read .children {display:none} and that didn't seem to do anything either...
zepponet
Member
Posted 4 years ago #
I have used Fold Category plugin for that with WP 2.1, but I am not sure if it works also with WP 2.3?
jwesseldyke
Member
Posted 4 years ago #
Yeah, I tried that, but either I wasn't using it correctly or it didn't work with 2.3. Listing both the parent and child categories is cumbersome and confusing... I'd even be content with the menu tree, and I can't get them to work either...
landersims
Member
Posted 4 years ago #
Even with the Fold Categories plugin the "children=0" boolean doesn't seem to work.