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
wp_list_cats()
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
E.g.
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 4I.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 ancestorsResult: (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:
Car
Home
Pets
-Cats
–Poppy (not linked, I’m already there!)
—Quirks
—Annoyances
–Skimble
–Tiddles
ZoosIf I now navigate to the ‘Cats’ Category, I’d see this:
Car
Home
Pets
-Aardvarks
-Cats
–Poppy (not linked, I’m already there!)
–Skimble
–Tiddles
-Chinchillas
-Dogs
ZoosSo 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
- The topic ‘Category List Manipulation’ is closed to new replies.