php - 将嵌套 ACF 中继器字段输出为简码中的表
问题描述
我正在尝试通过 elementor 页面上的简码在表格中显示嵌套的 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');
推荐阅读
- ios - 如何在更新它显示的对象数组时更新 SwiftUI 中的 ScrollView?
- python - Dask Dataframe .read_csv 不尊重 dtypes
- html - 角材料卡布局
- git - 为什么不能推送第二个克隆存储库?
- dataframe - Spark Streaming Dataframe 执行,有状态,分区本地 groupBy,避免洗牌
- arrays - 从对象数组中提取一个键值对的数组,同时基于另一个键值对进行过滤
- docker - 无法在 docker 入口点脚本中捕获信号
- python - 在超参数调整期间分数保持不变
- reactjs - url状态更改后自定义useFetch Hook不起作用
- java - 将文件中每个 int 的值分配给字符串