views:

282

answers:

1

I have a group of categories where the slug of each has a prefix "mycat-" and I would like to insert code into my sidebar.php file to create a custom sidebar widget that lists all categories except those preceeded by "mycat-".

Any help much appreciated.

Example Categories (by slug)...

mycat-hidden, mycat-favorites, mycat-nofollow, mycat-noindex, favorites, recently-updated, hot-links, etc

Given the above categories, I'd want the listing to be:

  • Favorites
  • Recently Updated
  • Hot Links
+1  A: 

You want to use this function.

wp_list_categories('exclude_tree=ID_OF_MYCAT');

Just insert your mycat parent category in there.

If you haven't set up your categories in a tree structure then you should consider doing so!

Rupert
Not sure I understand. My categories don't have parent/child relationships. They are all top level. Also, there is no single "mycat" category. I'm just using that as a prefix (thinking it would be set up for a regex filter). Does this help?
Scott B
Thanks Rupert, I'm working on using the parent category now, however, how do I exclude the parent category from the listing? Alternately, I suppose I could just add my categories to uncategorized (rather than creating a category to serve as the parent category). I'd prefer not though.
Scott B
Not quite sure what you mean here. If you mean you have a parent category mycat and then mycat-hidden etc. Then exclude_tree will get exclude the parent and its children, I believe.
Rupert