I'm using Bootstrap carousel to display 3 comments of a specific post in WordPress and the latest comment must have the active class on the div. However, the code that I have adds the active class to all 3 comments. Hence, all 3 shows in a single carousel block, where it should be divided or paginated by 3. Here is my current code:
<?php
$args = array(
'status' => 'approve',
'number' => '1',
'post_id' => 9,
'orderby' => 'comment_date',
'order' => 'DESC'
);
$comments = get_comments( $args );
foreach ( $comments as $comment ) :
echo '<div class="carousel-item active">
<div class="carousel-caption">
<span class="fad fa-quote-right" aria-hidden="true"></span>';
comment_text();
echo '<div id="image-caption">— <a href="'.$comment->comment_author_url.'" target="_blank">'.$comment->comment_author.'</a></div>
</div><!-- carousel-caption -->
</div><!-- carousel-item -->';
endforeach;
?>
I would like to have a condition where if comment is latest, add $active = ' active'; else, show nothing to the <div class="carousel-item'.$active.'">.
Is this possible?