I am trying to add specific CSS post classes to the services
custom post type. However, when I apply this function to the post class filter, it applies the function to all post types. My goal is to change the layout services
archive page with CSS classes.
Is the problem with the if ( is_singular('services') )
portion or does it have to do with the global $wp_query;
which might be querying every post? Any solution would be greatly appreciated.
The full code:
add_filter( 'post_class', 'woo_custom_add_post_classes', 10);
function woo_custom_add_post_classes ( $classes ) {
if ( is_singular('services') ) { return $classes; }
global $wp_query;
// Get the number of the current post in the loop.
$current_count = $wp_query->current_post + 1;
// Work out whether this post is the last in a row.
$iflast = 'last';
if ($current_count % 3 == 0 ) { $iflast = 'last'; } else { $iflast = '';}
// Add the classes to the array of CSS classes.
$classes[] = 'service-number-' . $current_count; // Service number.
$classes[] = 'threecol-one';
$classes[] = $iflast; // Last in the row or nothing
return $classes;
} // End woo_custom_add_post_classes()
if ( is_singular('services') ) { return $classes; }
...I think you meanif ( ! is_singular('services') ) { return $classes; }
?