how could i get for every post on a page a post_class “first”?
with this code a managed a class “first_post” for the really first post of the loop, but i need it also on the second, third and so on page of the loop.
function.php
function firstpost_class($class) {
global $post, $posts;
if ( is_home() && !is_paged() && ($post == $posts[0]) ) $class[] = 'firstpost';
return $class;
}
add_filter('post_class', 'firstpost_class');
Thanks for your help. Google couldn’t help yet.
I’ve seen this kind of thing done on the loop itself — comment to clarify if you want to do this site-wide, or particularly want to hook into post_class (then again, you can edit loop.php or a content-LOOPTYPE.php and reuse it over and over). Here’s an example loop:
This would give you item-1, item-2, etc. etc.