Support » Themes and Templates » Category List Manipulation

  • This probably sounds more complex than it need be, I’ve strived to be as complete as possible in the specification of the question!

    Thanks in advance for any assists.

    I’m getting in a twist as I can’t get
    to quite do what I need.

    Essentially, I would like to (when on an index page) show only parent categories. Easy

    HOWEVER, when on a category page, so the children of JUST the current category (whatever that might be). However, I don’t seem to be able to get the category ID easily.

    Ideally, there’d be an option to minimise the cats shown

    When on Child 3, a subcat of Parent 2, this would be the result:

    Parent 1
    Parent 2
    -Child 1
    -Child 2
    -Child 3
    –Grandchild 1
    –Grandchild 2
    -Child 4
    Parent 3
    Parent 4

    I.e. I want to try and work it up so that on any given category page, one can see the ‘root’ categories, any ‘ancestor’ categories, any ‘sibling’ categories, and the first generation of descendents.

    I’d settle as a stopgap for two lists, one showing descendents of the current category (I am stuck here) and one showing the root categories (easy).

    Ideally, I’d be able to say

    ‘List the root Ancestor categories alphabetically until you get to the root Ancestor of THIS category
    – now show all the Ancestors of this category (or just the parent)
    – now show the siblings of this category (stopping on this category)
    – Put in this category name and list the children of this category beneath it
    – Show any remaining siblings
    – Show any remaining root ancestors

    Result: (When in the category ‘Poppy’, which is a subcat of ‘Cats’, and has subcats of ‘quirks’, ‘annoyances’. ‘Skimble’ is also a cat, as is ‘Tiddles’)

    Car, Home, Pets and Zoos are master categories.

    Of course, the thing would be a semantically correct list:

    –Poppy (not linked, I’m already there!)

    If I now navigate to the ‘Cats’ Category, I’d see this:

    –Poppy (not linked, I’m already there!)

    So this is in two parts:

    The stopgap: How do I get the category ID on a category page (the ID isn’t in the URL)

    The ideal: How to display a list of categories showing only the top level cats and those cats which are the ‘closest relatives’ to the current cat (i.e. the parent, the children and the siblings)

    Any ideas?

    Thanks in advance

Viewing 6 replies - 1 through 6 (of 6 total)
  • I have a solution, it’s not quite what I want – I’d have liked to be able to put it into the appropriate place of the parent category list. It relies on the breadcrumbs plugin for the parents.

    <?php if (is_category()) { ?>
    <li class="related">
    <h2>Related Categories</h2>

    <?php if (function_exists('breadcrumb')) {
    } ?>

    $query='child_of=' . $cat;


    <?php } ?>

    I also have the following style declared:

    li.related ul.children {display: none;}

    To see it in action, look here and click around ‘related links’.

    Ideally, I’d like to do it entirely with native wp commands (i.e. not reliant on plugin). However, until then….

    Semantically, the parent categories should be nested lists, but I couldn’t see how to make that work at all!

    I really like your original idea. I tried to get WP to do something similar on my blog, but couldn’t figure it out.

    Fold catagory list:
    does something similar, but doesn’t explicity show the hierarchy.

    I’m glad it’s not just me… I’m hoping that someone with the skills to do something about it also likes it!

    Of course, the list would have appropriate classes built into each list item, things like ‘thiscat’, ‘sibling’, ‘parent’, ‘child’ and so forth!

    The ‘Fold Category’ thing looks pretty close. I’ll have to explore it.


    Your description of requirements (unless I’m missing something) is exactly what Fold Category List is designed to do.

    If you are having problems getting it to work, please contact me via the email address in the header of the plugin.

    Best regards


    I’ve got it going, though I have yet to style it. It’s hidden under an ‘if this function is available’ thing at the moment with the plugin disabled until I get a chance to style nicely.


    I need something like this, but the Fold Category List seems to work specifically with only the sidebar.php file. I would prefer to have my foldable categories in a separate page (not a menu but it becomes a standalone directory of sorts) as I have over 1,000 categories and subcategories.

    How do I do this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Category List Manipulation’ is closed to new replies.