<?php if (have_posts()) : $postCount = 0; while (have_posts()) : $postCount++; ?>
The above piece of code will create a $postCount
variable and increment it every time The Loop loops. Note that I've changed it to start at 0 instead of 1.
We now have the post count in $postCount
variable. We just need to find the first post and apply the styles to that post.
Normally, you'll have something like this:
<div class="post" id="post-<?php the_ID(); ?>">
Change that to:
<div <?php if($postCount == 1) { ?>class="YourSpecialClass"<?php }
else { ?>class="post"<?php } ?> id="post-<?php the_ID(); ?>">
The above code will check if the $postCount
is 1
(first post), and then add the class="YourSpecialClass"
part as its <div>
attribute.
A better readable version:
<?php if($postCount == 1) { ?>
//the first post -- style it
<?php } else { ?>
//other posts -- proceed normally
<?php } ?>
Hope this helps!