Hey Shelly,
You would be better off defining a function in your themes'
functions.php file that adds the post category to the post_class filter
hook on the post container.
For example:
<?php
// Practically verbatim from the
WordPress codex
//
http://codex.wordpress.org/Function_Reference/post_class#Add_Classes_By_Filters
add_filter('post_class','MYTHEME_post_class_cats');
function
MYTHEME_post_class_cats($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category) {
$classes[] =
$category->category_nicename;
return $classes;
}
} //
MYTHEME_post_class_cats($classes)
?>
All this does is it uses the post ID to determine its
category, and then adds the category slug name to the array of html
class attributes that are outputted when the page loads.
So you effectively get this as your markup:
...
<div id="post-example-342"
class="post single hentry POST_CATEGORY">
...
Where POST_CATEGORY is actually the lowercase hyphenated slug which you
can then target in your theme CSS as you were attempting to do before.
You can also add any classes names/strings you want by using
$classes[] =
'your-string-here'.$orStringVariable; which appends your new
string to the array.
Hope this helps,
Saturday, April
28, 2012 2:38 PM