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



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

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

中继器部分取自此链接: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');

部分解决.. 做更多的研究/挖掘 我注意到,由于这些设置即将进入 ACF 选项页面,我们需要为代码的某些部分添加一个"选项"这里是工作代码

现在我已经正确显示所有内容,有没有办法将每个"周"显示为自己的选项卡,并带有自己的相应表格?


function menu_loop() {
    ob_start();
    ?> 
     <?php if ( have_rows('menu','option') ):
        while ( have_rows('menu','option') ) : the_row(); ?>
            <h2 class="menu-title"><?php the_sub_field('week'); ?><h2>
            <?php if ( have_rows('week','option') ): ?>
                <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','option') ) : the_row(); ?>
                        <tr class="menu-row">
                            <td><?php the_sub_field('days','option'); ?></td>
                            <td><?php the_sub_field('snack_am','option'); ?></td>
                            <td><?php the_sub_field('lunch','option'); ?></td>
                            <td><?php the_sub_field('snack_pm','option'); ?></td>
                        </tr>
                    <?php endwhile;?>
                </table>
            <?php endif;?>
        <?php endwhile;?>
        <?php endif; ?>
    <?php
    return ob_get_clean();
}
add_shortcode('menushortcode', 'menu_loop');

最新更新