Sometimes you just need a list of all child categories only and nothing else. The requirements of projects can be very diverse, as the solution can, and in my case it is a small code snippet that takes care of the output of Subcategories. Something for you to play, improve and expand. Enjoy!
$echo = '
- ' . "\n";
$childcats = get_categories('child_of=' . $cat . '&hide_empty=1');
foreach ($childcats as $childcat) {
if (1 == $childcat->category_parent) {
$echo .= "\t" . '
- '; $echo .= $childcat->cat_name . ''; $echo .= ' ' . "\n"; } } $echo .= '
Comments
3 responses to “List All Subcategories”
Ehm, maybe I’m stupid, but why don’t you use http://codex.wordpress.org/Template_Tags/wp_list_categories? It got child_of as well.
Or you mean to list only subcategories without parent categories, but mixed together? I would not much understand this need, but again it could be done with wplist categories and some simple regexp, what would probably be a bit faster than this.
[…] List All Subcategories %CONTENT% […]
Hi Tomáš, the code is only to display the subcategories, nothing more.