http://codex.wordpress.org/Function_Reference/get_the_category
http://codex.wordpress.org/Function_Reference/get_categories
<?php $cats = get_the_category($post->ID);
foreach( $cats as $cat ) {
$subcats = get_categories('child_of='.$cat->term_id);
$kits = array();
if($subcats) {
foreach( $subcats as $subcat )
{ $subcategories[] = $subcat->slug; }
}
}
$subcategories = array_unique($subcategories);
if($subcategories) {
$subcategories = implode(' ',$subcategories);
echo 'class="' . $subcategories . '"';
}
?>
Thanks for that, but it’s not quite working the way I want…
So inside of the main loop (index.php) I have it targeting the specific category
<?php query_posts('cat=14&showposts=3'); ?>
<?php $posts = get_posts('category=14&numberposts=3&offset=0');
foreach ($posts as $post) : start_wp(); ?>
Then I have a ul with the li’s inside of that. I want to give each li in the loop a class of all the sub-categories that is assigned to it. For example
<ul>
<li class="Video Project"></li>
<li class="Project About"></li>
</ul>
When I was using your code that you provided earlier I was getting some sub-categories names as Blog-Video. (Blog is the main Category)
So in the above example I want to only have the sub-categories of category 14 (bold above) to show up.