Add a post class to the first post in a loop
Published onI’m sure you could also do this with pre_get_posts
, but this works nicely, replacing post_class()
within the article
block.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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.