如何使用子字段的条件进行 WHILE
How to do a WHILE with condition of a subfield
我正在尝试在 3 列 li 中显示内容。
到目前为止一切顺利,但我想设置为只出现以字母 A、B 或 C 开头的单词。
问题是我只设法创建了创建 li 的条件,因此,代码正在创建空字段。
所以 我的问题是 是否有办法在 while.
中创建此条件
我的代码 [已更新][已更新为可用版本]
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') ):
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; ?>
不确定您要做什么,但请看下面的内容:
<?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 }
}
}
}
?>
我正在尝试在 3 列 li 中显示内容。 到目前为止一切顺利,但我想设置为只出现以字母 A、B 或 C 开头的单词。
问题是我只设法创建了创建 li 的条件,因此,代码正在创建空字段。 所以 我的问题是 是否有办法在 while.
中创建此条件我的代码 [已更新][已更新为可用版本]
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') ):
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; ?>
不确定您要做什么,但请看下面的内容:
<?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 }
}
}
}
?>