I'm pulling all attachments for this particular post and displaying them in a carousel. Problem is I need to give the first item a class of active so bootstrap carousel will work.
Here is my loop:
<?php foreach ( $attachments as $attachment ):
$description = $attachment->post_content;
echo '<div class="item" data-description="' . $description . '">';
echo wp_get_attachment_image($attachment->ID, 'large');
echo '</div>';
endforeach;
?>
I've tried:
<?php $isFirst = true; ?>
<?php foreach ( $attachments as $attachment ):
$description = $attachment->post_content;
echo '<div class="item' . $isFirst ? ' active' : '' . '" data-description="' . $description . '">';
echo wp_get_attachment_image($attachment->ID, 'large');
echo '</div>';
endforeach;
?>