猿问

将嵌套的 ACF 中继器字段输出为简码中的表格

我正在尝试通过元素页面上的短代码在表格中显示嵌套的 ACF 字段。


我尝试将短代码与我在 google 上找到的一些代码合并,但是我没有成功。


转发器部分取自此链接:https : //support.advancedcustomfields.com/forums/topic/help-with-creating-a-table-using-nested-repeaters/


当我使用短代码时,什么都没有。


function menu_loop() {

    ob_start();

    ?> 


     <?php if ( have_rows('menu') ):


        while ( have_rows('menu') ) : the_row(); ?>


            <h2 class="menu-title"><?php the_sub_field('week'); ?><h2>


            <?php if ( have_rows('week') ): ?>


                <table>


                    <thead>

                        <tr class="menus-row">

                            <td>Days</td>

                            <td>Snack AM</td>

                            <td>Lunch</td>

                            <td>Snack PM</td>

                        </tr>

                    </thead>


                    <?php while ( have_rows('week') ) : the_row(); ?>


                        <tr class="menu-row">

                            <td><?php the_sub_field('days'); ?></td>

                            <td><?php the_sub_field('snack_am'); ?></td>

                            <td><?php the_sub_field('lunch'); ?></td>

                            <td><?php the_sub_field('snack_pm'); ?></td>

                        </tr>


                    <?php endwhile;?>


                </table>


            <?php endif;?>


        <?php endwhile;?>

        <?php endif; ?>


    <?php

    return ob_get_clean();

}

add_shortcode('menushortcode', 'menu_loop');


Smart猫小萌
浏览 135回答 1
1回答

莫回无

部分解决..做更多的研究/挖掘我注意到,由于这些设置即将出现在 ACF 选项页面,我们需要在代码的某些部分添加一个“选项”,这里是工作代码现在我已经正确显示了所有内容,有没有办法将每个“周”显示为它自己的选项卡和它自己的相应表格?function menu_loop() {&nbsp; &nbsp; ob_start();&nbsp; &nbsp; ?>&nbsp;&nbsp; &nbsp; &nbsp;<?php if ( have_rows('menu','option') ):&nbsp; &nbsp; &nbsp; &nbsp; while ( have_rows('menu','option') ) : the_row(); ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h2 class="menu-title"><?php the_sub_field('week'); ?><h2>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php if ( have_rows('week','option') ): ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <table>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <thead>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr class="menus-row">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>Days</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>Snack AM</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>Lunch</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>Snack PM</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </thead>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php while ( have_rows('week','option') ) : the_row(); ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr class="menu-row">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php the_sub_field('days','option'); ?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php the_sub_field('snack_am','option'); ?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php the_sub_field('lunch','option'); ?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php the_sub_field('snack_pm','option'); ?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php endwhile;?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </table>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php endif;?>&nbsp; &nbsp; &nbsp; &nbsp; <?php endwhile;?>&nbsp; &nbsp; &nbsp; &nbsp; <?php endif; ?>&nbsp; &nbsp; <?php&nbsp; &nbsp; return ob_get_clean();}add_shortcode('menushortcode', 'menu_loop');
随时随地看视频慕课网APP
我要回答