how to add a “active” class to first loop item in WordPress Query?

I am having a query as shown below. I want to add a “active” class only to first loop item.

class=”carousel-item col-md-4 active”

$query= new WP_Query($wpplnum);

while($query->have_posts()):$query->the_post();

?>

<div class=”carousel-item col-md-4 active”>
<div class=”card”>
<img class=”card-img-top img-fluid” src=”http://placehold.it/800×600/f44242/fff” alt=”Card image cap”>
<div class=”card-body”>
<h4 class=”card-title”>Card 1</h4>
<p class=”card-text”>This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<p class=”card-text”><small class=”text-muted”>Last updated 3 mins ago</small></p>
</div>
</div>
</div>

Read more here:: how to add a “active” class to first loop item in WordPress Query?

Leave a Reply

Your email address will not be published. Required fields are marked *