wp_query, give first post different formatting

I want to be able to give the first post in a custom instance of wp_query different formatting to the rest.

This is a sample of my current loop (With some bits simplified to shorten my code);

Read More
$args1 = array(
    'post_type' => 'post',
    'posts_per_page' => 4
);
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post();
    echo '<h2><a href="'.the_permalink().'">'.the_title().'</a></h2>';
endwhile; wp_reset_postdata();

But for the first post in this loop I want to formatting to be different so that I can show the post thumbnail, a short content excerpt, etc.

Related posts

1 comment

  1. Hope I’m understanding you correctly could you not just do something simple like this

    $args1 = array(
        'post_type' => 'post',
        'posts_per_page' => 4
    );
    $loop = new WP_Query($args);
    while ($loop->have_posts()) : 
        $loop->the_post();
        echo '<h2><a href="'.the_permalink().'">'.the_title().'</a></h2>';
        if ($loop->current_post == 0) {
              echo the_post_thumbnail();
              echo the_excerpt();
        }
    endwhile; wp_reset_postdata();
    

Comments are closed.