Add a Special Class for the First Post in the Loop

add_filter( 'post_class', 'post_class_example' );
 
function post_class_example( $classes ) {
    global $wp_query;
    if ( 0 == $wp_query->current_post ) {
        $classes[] = 'first-post';
    }
    return $classes;
}

Leave a Reply