【发布时间】:2020-01-28 00:46:43
【问题描述】:
我正在尝试输出嵌套的 ACF 转发器字段,以便输出如下:
第 1 组名称
第 1 组值数组:
- 捐赠者姓名
- 公司名称
- 照片网址
第 2 组名称
第 2 组值数组:
- 捐赠者姓名
- 公司名称
- 照片网址
到目前为止,我有以下代码:
$sponsor_group_names = array();
$donor_names_list = array();
$donor_company_names_list = array();
$donor_photo_urls = array();
$donors_group_list = array();
if (have_rows('sponsor_group')):
while ( have_rows('sponsor_group')) : the_row();
$sponsor_group_name = get_sub_field('sponsorship_group_name');
array_push($sponsor_group_names, $sponsor_group_name);
if (have_rows('group_donors')):
while ( have_rows('group_donors')) : the_row();
$donors_group = get_field('group_donors');
array_push($donors_group_list, $donors_group);
$donor_name = get_sub_field('donor_name');
array_push($donor_names_list, $donor_name);
$donor_company_name = get_sub_field('donor_company_name');
array_push($donor_company_names_list, $donor_company_name);
$donor_photo = get_sub_field('donor_photo');
array_push($donor_photo_urls, $donor_photo);
endwhile;
endif;
endwhile;
endif;
我输出如下:
<?php foreach ($sponsor_group_names as $group): ?>
<h2 class="text-primary mb-3">{{$group}}</h2>
<div class="row" style="margin-bottom: 0 !important">
<?php
$iterator = 0;
foreach ($donor_names_list as $donor): ?>
<div class="col-md-4 contact-card" style="min-width: 300px;">
<div class="row" style="margin-bottom: 0 !important">
<div class="col-lg col-6"><img src="{{$donor_photo_urls[$iterator]}}" class="donor-photo"></div> <!--https://via.placeholder.com/100-->
<div class="col-lg col-6 donor-info"> <p>{{$donor}} </p> <p> {{$donor_company_names_list[$iterator]}} </p></div>
</div>
</div>
<?php $iterator++;
endforeach; ?>
</div>
<?php endforeach; ?>
此输出为我提供了 1 和 2 的不同组名称,但为公司名称、照片 url 和捐赠者名称输出相同的信息。理想情况下,我希望设置我的代码,以便它使用 key=>value 之类的 $donor_photo_urls['group 1'],但我之前尝试模仿我在 ACF 支持论坛上看到的内容导致 NULL 输出。
最终我想为每个组名打印唯一的数组。感谢任何帮助!
【问题讨论】:
-
您可以发布您的中继器设置的屏幕抓图(或 JSON)吗?
标签: php wordpress advanced-custom-fields