Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据ACF repeater字段中的PHP变量添加div类?_Php_Advanced Custom Fields - Fatal编程技术网

根据ACF repeater字段中的PHP变量添加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

我在高级自定义字段中循环遍历repeater字段,并显示repeater中每个项目的div。如果索引等于0,我想只向该div添加一个特殊类。这可能吗?以下是我尝试过的:

<?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; ?>

如果你找到了解决方案,关闭问题。我添加了答案,以防其他人需要它。。。。这不是这个网站的重点吗?