如何在子场的条件下做一段时间



我正在尝试进行一段时间,并在3列Li中显示内容。到目前为止还不错,但我想条件只能以字母A或b或c。

开头的单词

问题是我仅设法创建了创建 li 的条件,因此,代码正在创建空字段。因此,我的问题是如果有一种方法可以在中创建此条件,而

我的代码 [更新] [已更新为工作版本] ]

if( have_rows('insert_breed_name_to_add') ){
$count = 0;
while( have_rows('insert_breed_name_to_add') ){
    the_row();
    if(get_sub_field('breed_name')[0] == 'A' ){
            $count++;
            // If it is first time create "col-4"
            if($count == 1 || $count%3 == 1){ ?>
            <div class="col-4"><ul>
            <?php } ?>
            <!-- Create Li -->
            <li><?php the_sub_field('breed_name'); ?></li>
             <!-- close col-4 -->
            <?php if ($count%3 == 0){?>
                </ul>
            </div>
            <?php }
        }
     }
  }
?>

不确定您要做什么,但请看以下:

<?php
if( have_rows('insert_breed_name_to_add') ){
    $count = 0;
    while( have_rows('insert_breed_name_to_add') ){
        the_row();
        // If it starts from A or B or C
        if(get_sub_field('breed_name')[0] == 'A' || get_sub_field('breed_name')[0] == 'B' || get_sub_field('breed_name')[0] == 'C'){
                $count++;
                // If it is first time create "col-4"
                if($count == 1){ ?>
                <div class="col-4"><ul>
                <?php } ?>
                <!-- Create Li -->
                <li><?php the_sub_field('breed_name'); ?></li>
                 <!-- close col-4 -->
                <?php if ($count%3 == 0){?>
                    </ul>
                </div>
                <?php }

        }
    }
}
?>
    <?php if( have_rows('insert_breed_name_to_add') ):
    while( have_rows('insert_breed_name_to_add') **MAYBE INSERT CONDITION HERE? BUT HOW?** ): the_row();
while (have_rows('your_custom_field_values') ): the_row();
    $count = 1;
    if ($count%3 == 1)
    {?>
     <div class="col-4"><ul>
     <?php } ?>
     <? if( get_sub_field('breed_name')[0] == 'a' OR get_sub_field('breed_name')[0] == 'A'){ ?>
     <li><?php the_sub_field('breed_name'); ?></li>
      <?php }?>
      <?php if ($count%3 == 0){?>
      </ul></div>
      <?php }
      $count++;
      if ($count%3 != 1)?>
      </ul>
      </div>
      <?php endwhile; ?>
      <?php endwhile; ?>
      <?php endif; ?>

相关内容

最新更新