P粉8199374862023-09-06 00:12:16
以您想要開始的數字建立一個變量,例如1,然後使用PHP 的後增量 $a
在您循環處理下一個選項卡或內容時增加其值。
<ul class="nav nav-tabs" id="myTab" role="tablist"> <?php $tabIndex = 1; $tabs = get_field('tab'); if( $tabs ) : foreach( $tabs as $tab) : $headline = $tab['headline']; ?> <li class="nav-item" role="presentation"> <a class="nav-link<?php if ($tabIndex === 1) { echo ' active'; } ?>" id="home-tab" data-toggle="tab" data-target="#tab-<?php echo $tabIndex; ?>" type="button" role="tab" aria-controls="home" aria-selected="true"> <?php echo $headline; ?> </a> </li> <?php $tabIndex++; ?> <?php endforeach; ?> <?php endif; ?> </ul> <div class="tab-content page" id="myTabContent"> <?php $tabIndex = 1; $tabs = get_field('tab'); if( $tabs ) : foreach( $tabs as $tab) : $description = $tab['description']; ?> <div class="tab-pane fade show<?php if ($tabIndex === 1) { echo ' active'; } ?>" id="tab-<?php echo $tabIndex; ?>" role="tabpanel" aria-labelledby="tab-<?php echo $tabIndex; ?>"> <p> <?php echo $description; ?> </p> </div> <?php $tabIndex++; ?> <?php endforeach; ?> <?php endif; ?> </div>