• 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

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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>
    ';
    }
    ?>

    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…

    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?

    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…

    Even with the Fold Categories plugin the “children=0” boolean doesn’t seem to work.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Category list of parent categories only’ is closed to new replies.