クラス名にインクリメントを追加できる必要があります。私はこれのための解決策を探しましたが、私の例ではうまくいきません。CSSクラスにインクリメントを追加する
私は、クラス 'section_0'に連続番号1,2,3,4などを追加したいforeachループを持っています。私が間違っていることは何ですか?
<div class="menu-section-container">
<?php
// check if the repeater field has rows of data
if(have_rows('section_container')):
// loop through the rows of data
while (have_rows('section_container')) : the_row();
if(have_rows('sub_section_container')):
// loop through the rows of data
while (have_rows('sub_section_container')) : the_row();
if(have_rows('food_item')):
// loop through the rows of data
while (have_rows('food_item')) : the_row();
$menu_contents = array(the_sub_field('section_heading'), the_sub_field('item_name'), the_sub_field('price'), the_sub_field('item_description'));
$counter = 1;
foreach ($menu_contents as $menu_content); { ?>
<div id="section_0<?php echo $counter++; ?>" class="tabcontent">
<?php echo $menu_content; ?>
</div>
<?php $counter++; // increment before foreach ends
}
endwhile;
else :
endif;
endwhile;
else :
endif;
endwhile;
else :
endif;
wp_reset_postdata();
?>
</div> <!-- section -->
出力はあなたの何を得ていますか? –
@NigelRen Redクラス名と各グループの番号1を返します。したがって、基本的に "section_01"、 "section_01"、 "section_02"、 "section_03"などではありません。 – Paul
インデントにはコード構造が反映されていることを確認してください。それはあなたにかなりの頭痛を救うでしょう。 – jcaron