我当前的代码,它有效。
我的目标:
我想要一个“不可用”尺寸的复选框,所以如果我选中该框,它将为 tr 行添加 class="na",因此它的颜色为灰色。
我该如何实现?
尺码指南
<section class="row-wrap">
<div class="row-inner">
<table class="size-guide" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th>UK</th>
<th>EU</th>
<th>Chest(cm)</th>
<th>Chest(in)</th>
<th>Height(cm)</th>
</tr>
<?php
// check if the repeater field has rows of data
if( have_rows('size_guide') ):
// loop through the rows of data
while ( have_rows('size_guide') ) : the_row(); ?>
<tr class="na">
<td><?php the_sub_field('uk'); ?></td>
<td><?php the_sub_field('eu'); ?></td>
<td>$<?php the_sub_field('chest_(cm)'); ?></td>
<td><?php the_sub_field('chest_(in)'); ?></td>
<td>$<?php the_sub_field('height_(cm)'); ?></td>
</tr>
<?php endwhile;
else :
// no rows found
endif;
?>
</tbody>
</table>
</div>
</section>
<!-- /size guide -->
最佳答案
好吧,假设您在转发器字段中添加了一个名为可用的复选框。您只需选中该复选框值即可。如果等于 no 添加你的 na 类。
<tr class="<?php if (get_sub_field('available') === 'No') {echo 'na';} ?>">
<td><?php the_sub_field('uk'); ?></td>
<td><?php the_sub_field('eu'); ?></td>
<td>$<?php the_sub_field('chest_(cm)'); ?></td>
<td><?php the_sub_field('chest_(in)'); ?></td>
<td>$<?php the_sub_field('height_(cm)'); ?></td>
</tr>
关于php - 如何为自定义字段中继器添加复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42877164/