I'm a little bit out of practice and struggling to figure out some fairly basic PHP to get the result I'm after. I have the following code:
<?php //My ACF Fields for reference //faqs - field group //faq_question - sub-field //faq_answer - sub-field // check if the repeater field has rows of data if( have_rows('faqs') ): ?> <div class="accordion" id="accordion2"> <?php $i=1; while ( have_rows('faqs') ) : the_row(); ?> <div class="accordion-group"> <div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapse<?php echo $i; ?>"> <?php the_sub_field('faq_question'); ?> </a> </div> <div id="collapse<?php echo $i; ?>" class="accordion-body collapse"> <div class="accordion-inner"> <?php the_sub_field('faq_answer'); ?> </div> </div> </div><!-- ACCORDIAN GROUP END --> <?php $i++; endwhile; ?> </div> <?php endif; ?>
I simply want the 1st accordion group to have a slightly different class to any that follow it. It's so that the 1st accordion item is open with the other's closed once the page loads. I've tried doing something along the lines of <?php if $i=1 ?> but keep managing to break it. Hopefully that makes some sense?