First of all, never use query_posts
, use WP_Query
to create additional queries.
You can target specific post positions in the loop by using the built in current_post
var of the query object.
Here’s an example using the post_class
function:
<?php
$my_posts = new WP_Query( array( 'posts_per_page' => 3 ) );
if( $my_posts->have_posts() ):
while( $my_posts->have_posts() ):
$my_posts->the_post();
?>
<div <?php post_class( 'index-' . ( $my_posts->current_post + 1 ) ); ?>>
<p class="lm">Learn More</p>
</div>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
Then in your CSS:
.index-1 .lm { /* styles for 1st post */ }
.index-2 .lm { /* styles for 2nd post */ }
.index-3 .lm { /* styles for 3rd post */ }