php - 如何为自定义字段中继器添加复选框?

标签 php jquery css wordpress advanced-custom-fields

我当前的代码,它有效。

我的目标:

我想要一个“不可用”尺寸的复选框,所以如果我选中该框,它将为 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/

相关文章:

javascript - 将变量传递给jquery上传函数

javascript - 使用 JavaScript 或 CSS 缩放每一行中的图像以 100% 填充它

javascript - 如何重绘jquery数据表?

php - 如何在 Android TextView 上获取不断更新的 mysql 行数?

php - CakePHP 重定向状态代码 404

php - 将用户指定的日期和时间(使用 mktime 转换)调整为特定时区

jquery - 通过自动页面滚动,单击时将 div 浮出窗口顶部

javascript - 如何使用与 PHP <li> 不同的值运行 onClick 函数?

html - 如何使背景标题图像扩展到浏览器的全宽

html - 页脚不动态适应页面大小