If you want to add some … uh … excuse the pun … class to the first post listed on your WordPress blog, here’s the solution. Maybe you hadn’t even thought of such a thing, but now that I’ve mentioned it, your creative mind has been flipped-on. 😉
As with many WordPress mods, all you’ll have to do is add your snippet into your functions.php.
How-To Add Some Class
Drop this into your functions.php or functionality plugin:
add_filter( 'post_class', 'wps_first_post_class' );
function wps_first_post_class( $classes ) {
global $wp_query;
if( 0 == $wp_query->current_post )
$classes[] = 'first';
return $classes;
}
This particular example ads the class name “first,” but you can name it to whatever you like.
With this in place, your WordPress theme will add the class “first” to the first post in your WordPress Loop.
[via WP Snipp]
Craig Allen says
This is great, I can already think of a few interesting ways to use this. Thanks!
Eric Dye says
Sweet!