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?
Aucun commentaire:
Enregistrer un commentaire