Getting cat-category_nicename as class only if has_category
-
I’m currently displaying a class on post items like
cat-category_nicename
(i.e.cat-press
) using the below:-$categories = get_the_category($post->ID); foreach( $categories as $category ) { // Category Class $cat_class = 'cat-' . $category->category_nicename; }
But on custom post types,
has_category
returns false and with the above, a class is output (the same one for all custom post types of a category – which it doesn’t belong to).How can I only display
$cat_class
if the post belongs to a category?I might be worth noting that I am currently display
$cat_class
inpost_class
currently like below:-post_class("item mix $wrapper_class $cat_class", $post->ID );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Getting cat-category_nicename as class only if has_category’ is closed to new replies.