The $current_post
property of the WP_Query
object for the Loop should tell you which post you are on. Something like this should work:
<?php $pclass = ($wp_query->current_post === 1) ? 'middle-post-class' : 'first-last-class' ; ?>
<div id="post-style" <?php post_class($pclass); ?> >
<h1 class="title"><a href="https://wordpress.stackexchange.com/questions/87942/<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
</div>
The built in Loop counter– $current_post
— starts from 0. That is why the second post is 1, and not 2.
Caveats: Your theme may already be using post_class
somewhere else. You may not want to use it a second time. And if this is a custom WP_Query
Loop the name of the object may be different– that is, $my_query
instead of wp_query
, for example.