"even/odd" classes and custom queries
-
Greetings! Thanks for the awesome theme!
I have a custom home.php template that displays only posts in a custom post type on my homepage. But I’ve found that creating a new WP_Query to grab theses breaks the nifty “even/odd” class assigned to the posts in succession, so the featured images and excerpts now all fall on the same side, instead of being alternated. Can anybody help?
Here’s what I think the relevant function is:
function ct_tracks_odd_even_post_class( $classes ) {
// access the post object
global $wp_query;// add even/odd class
$classes[] = ($wp_query->current_post % 2 == 0) ? ‘odd’ : ‘even’;// add post # class
$classes[] = “excerpt-” . ($wp_query->current_post + 1);return $classes;
}
add_filter ( ‘post_class’ , ‘ct_tracks_odd_even_post_class’ );
- The topic ‘"even/odd" classes and custom queries’ is closed to new replies.