• Looking at the documentation page for wp_list_pages, there is a depth parameter:

    depth: (integer) Numeric value for how many levels are to be displayed in the hierarchy of pages. Defaults to 0 (display all pages); depth=-1 shows no child pages; depth=1 shows only the top pages; any value given greater than 1 displays the sub-pages up to that level in the pages hierarchy.

    At first glance, there is no such parameter available in the wp_list_categories tag. Any reason for this? This seems like a piece of functionality that is quite useful (for the same reason that it is useful in the wp_list_pages tag)

Viewing 7 replies - 1 through 7 (of 7 total)
  • great f***** question. i’ve been trying to figure this one out. found anything yet?

    i think i got something to work
    download and install this plugin
    http://braydon.com/unfold_list_categories.zip

    to only show 1 level of categories use this:
    <?php unfold_list_categories(‘depth=1&hierarchical=1’); ?>

    in place of this:
    <?php wp_list_categories(); ?>

    let me know if it works for you… it worked for me but it was sort of by accident i think

    Hello,

    when I used depth=1, then only main categories are shown.
    For example:
    Europe, Asia, etc.
    But when I used depth=2 then all categories are shown.
    For example:
    Europe – Germany, UK, etc.
    Is it possible to show only categories in second order? That means Germany, UK, etc. without this main category?

    that is a great question. and i would like to have this functionality too.

    from what it looks like. the ws_list_category function is calling a class called walker and walk_list_categories (need to check the name) they are both located in the classes.php file in the includes folder.

    the unfold_list_categories is essentially using functionality that already exists in the walker class, but because of the way the walker class is coded. it essentially walks down the tree, and if the depth is set to a number it doesn’t go down sub cats. i don’t think just getting the second level categories would be possible. we would need to modify the walker classes. i would like to try to do this.

    a way you might be able to get around this is to use the child_of argument, and have it do that for all categories…

    For some reason depth=# does nothing in WP 2.1.2….. Works in 2.1….. and previous not 2.1.2

    big thanx for this nice plugin, you made my day (night) 😀

    My solution to this problem:

    display: none;

    On the class of expanded ul or li, whatever the baby categories may be.

    Clearly this is not the most graceful solution ever, but it’s better than hacking code that won’t stay upon upgrade, and works better if you need to target the parent level cat in a way that’s incompatible with the plugin listed above.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘wp_list_categories Depth’ is closed to new replies.