根据ACF repeater字段中的PHP变量添加div类?
我在高级自定义字段中循环遍历repeater字段,并显示repeater中每个项目的div。如果索引等于0,我想只向该div添加一个特殊类。这可能吗?以下是我尝试过的:根据ACF repeater字段中的PHP变量添加div类?,php,advanced-custom-fields,Php,Advanced Custom Fields,我在高级自定义字段中循环遍历repeater字段,并显示repeater中每个项目的div。如果索引等于0,我想只向该div添加一个特殊类。这可能吗?以下是我尝试过的: <?php if (have_rows('products')): $i = 0; ?> <div class="product-container"> <?php while (have_rows('products')) : the_row(); ?> <div cl
<?php if (have_rows('products')): $i = 0; ?>
<div class="product-container">
<?php while (have_rows('products')) : the_row(); ?>
<div class="product <?php if ($i == 0) { echo 'active-class'; } ?>"></div>
<?php $i++; endwhile; ?>
</div>
<?php endif; ?>
不幸的是,这不起作用。我没有在类中执行条件,而是在外部执行,并根据条件定义了两个不同的类标记:
<?php if (have_rows('products')): $i = 0; ?>
<div class="product-container">
<?php while (have_rows('products')) : the_row(); ?>
<div <?php if ($i == 0) { ?>class="product active"<?php } else { ?>class="product"<?php } ?> ></div>
<?php $i++; endwhile; ?>
</div>
<?php endif; ?>
如果你找到了解决方案,关闭问题。我添加了答案,以防其他人需要它。。。。这不是这个网站的重点吗?