AJStacy
Member
Posted 3 months ago #
I'm trying to get the slug of the current posts category while inside of the loop. I feel like pulling my hair out because something that should be simple is turning out to be a big pain.
Is there something really easy I'm missing? How can I do this?
Ultimately I'm using the category slug name to output to match with a css class name for styling purposes. Please help!
$category = get_the_category();
$cat_=name = $category[0]->cat_name;
http://codex.wordpress.org/Function_Reference/get_the_category
if you would add post_class() to the post div, you would automatically get all sorts of category and tag specific css classes:
http://codex.wordpress.org/Function_Reference/post_class
AJStacy
Member
Posted 3 months ago #
Thanks! This worked perfectly!
$category = get_the_category();
$cat_=name = $category[0]->cat_name;