WordPress.org

Ready to get started?Download WordPress

Forums

Control child categories in WP 2.1 (4 posts)

  1. cousinagam
    Member
    Posted 7 years ago #

    Prior to 2.1, I set my sidebar to display only categories 2, 3, and 4, each of which has so many children that I don't want them to show in the sidebar. Instead each of these has its own category page (e.g., category-4.php) that lists all the children as links. (Category 1 was uncategorized, so I excluded it completely.) The old code:

    <?php wp_list_cats('exclude=1&children=0'); ?>

    With 2.1, I find that wp_list_cats is deprecated. I'm trying to get the same effect with wp_list_categories but am coming up short.

    wp_list_categories('title_li=&show_count=0&child_of=0&hierarchical=0&exclude=1');
    displays the children of categories 2, 3, and 4 but not the categories themselves.

    wp_list_categories('title_li=&show_count=0&child_of=0&hierarchical=1&exclude=1');
    displays the parents (2, 3, 4) and the children.

    wp_list_categories('title_li=&show_count=0&child_of=0&exclude=1');
    (which leaves out 'hierarchical') also displays both parents and children.

    I'm sure I'm overlooking something obvious, but as you can see it's not obvious to me.

    This is the site: Cousin Agam Fhèin

  2. cousinagam
    Member
    Posted 7 years ago #

    Just an update... poking around the Codex, I get the impression that 2.1x's changes mean I can't get wp_list_categories to do what I want (e.g., show only categories 2, 3, and 4 in the sidebar, <i>without</i> showing their children.

    A workaround came to me in the dentist's office:

    I added hyperlinks in the sidebar for the three category-specific pages. I entered a text label of "Categories" and under it put links to category-2.php, category-3.php, and category-4.php

    Works just fine.

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    I posted this in your other thread, but in case you don't see it:

    wp_list_categories('include=2,3,4');

    Where there is an exclude, there is usually an include as well.

  4. cousinagam
    Member
    Posted 7 years ago #

    Otto42,

    I used your format (include=2,3=4), but I'm still getting the children (e.g., children of 4) listed in the sidebar.

Topic Closed

This topic has been closed to new replies.

About this Topic