WordPress Snippets at WPcustoms

Add custom css class to first post

Add a custom css class to the first post in your WordPress loop.


/**
 * Snippet Name: Add custom css class to first post
 * Snippet URL: http://www.wpcustoms.net/snippets/add-custom-css-class-to-first-post/
 */
 function wpc_first_post_class( $classes ) {
    global $wp_query;
    if( 0 == $wp_query->current_post )
        $classes[] = 'first';
        return $classes;
}
add_filter( 'post_class', 'wpc_first_post_class' );