Matt Radford

Messing with links since <blink>

Add a post class to the first post in a loop

Published on 

I’m sure you could also do this with pre_get_posts, but this works nicely, replacing post_class() within the article block.

<?php
if ($wp_query->current_post == 0 && !is_paged()) :
$first = ( $wp_query->current_post == 0 && !is_paged() ) ? 'firstpost' : ''; post_class($first);
else :
post_class();
endif;
?>

Could also be done with CSS :first-child of course.