My theme has styling by category using the following code, which inserts the current category's slug as a CSS class.
<div class="CategorySpecificStyle <?php $category = get_the_category(); echo $category->slug; ?>"> <?php echo $category->cat_name; ?> </div>
Now i'm about to add a large number of new sub-categories, and it seems silly to add them all in CSS when I should be able to just select the parent category of the current post and apply styles to that.
I've been able to get the parent category's name:
$parentcat = get_cat_name($category->category_parent);
But spaces (and capitalization) is an issue... And I can't seem to get the parent category's slug.
I know i'm probably missing a simple step somewhere, but any insight would be greatly appreciated.