add a specific class to every second and third post in a group of 4 posts?
assuming that the post’s div has post_class()
, this is doable with using the $wp_query->current_post
of a default loop, in a filter function added to functions.php of your theme:
function special_recurrent_post_class($classes) {
if( is_home() ) {
global $wp_query;
$extra_classes = array('','specific','specific','');
$classes[] = $extra_classes[$wp_query->current_post%count($extra_classes)];
}
return $classes;
}
add_filter('post_class', 'special_recurrent_post_class');
(example restricts this to posts on the home page or posts page; for other, you need to change the coditional tag is_home()
to something else; http://codex.wordpress.org/Conditional_Tags
watch out:
the code is for a group of 4;
your example shows a group of 3 – be sure about what you want.
if this is not what you want, please post the existing code of the template – see forum guidelines http://codex.wordpress.org/Forum_Welcome#Posting_Code
Thread Starter
coke
(@coke)
wow, thank you so much! It works like a dream!