Answer the question
In order to leave comments, you need to log in
How to add class to ARTICLE but only in categories in wordpress?
There is this line:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<article id="post-18" class="post-18 post type-post status-publish format-standard hentry category-smart_chinese category-level_1">
class="itisentry post-18 post type-post status-publish format-standard hentry category-smart_chinese category-level_1"
'class1 class2 class3' );
post_class( <?php post_class( 'if (is_category()) { echo "itisentry"; }' ); ?>
Answer the question
In order to leave comments, you need to log in
So?
function category_id_class( $classes ) {
global $post;
foreach ( ( get_the_category( $post->ID ) ) as $category ) {
$classes[] = $category->category_nicename;
}
return $classes;
}
add_filter( 'post_class', 'category_id_class' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question