Home › Forums › General Issues › Add class "active" to first item; display first item › Reply To: Add class "active" to first item; display first item
Hi @toad78
Could you please wrap the <li>
code in the code tag? If you don’t wrap it, the page will look broken and it’s hard to understand your explanation.
Regarding your issue, it seems that you didn’t clear the $class
variable in each loop and didn’t clear the $c
variable at the end of the loop. Please try this code instead:
<div class="col-xs-6 left">
<ul class="nav nav-tabs tabs-left">
<?php $i = 0; ?>
<?php while( have_rows('features') ): the_row(); $i++; ?>
<li class="<?php if( $i ==1 ){ echo "active"; } ?>"><a href="#<?php echo the_sub_field('link_id');?>" data-toggle="tab"><?php the_sub_field('feature-title'); ?></a></li>
<?php endwhile; ?>
</ul>
</div>
<div class="col-xs-6">
<div class="tab-content">
<?php $i = 0; ?>
<?php while( have_rows('features') ): the_row(); $i++; ?>
<div id="<?php echo the_sub_field('link_id');?>" class="tab-pane fade in <?php if( $i ==1 ){ echo "active"; } ?>"><?php echo the_sub_field('feature-description'); ?></div>
<?php endwhile; ?>
</div>
</div>
I believe this is more of a PHP issue. For further support, please ask the PHP community.
Thanks!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.