ACF中继器字段显示
问题描述:
我已经在称为'成分'的帖子类型内创建了一个名为'products'和自定义分类的自定义帖子类型。ACF中继器字段显示
我添加了一个名为'ingredients-INCI'的repeater字段和'ingredients-INCI-group'的子字段,它调用分类'成分'中的值。
定制中继字段截图:
每个产品都有许多成分,我想显示该产品的选择的成分列表。这里是我的模板代码:
<?php
/**
PostType Page Template: Product
*/
get_header(); ?>
\t <div id="b_primary" class="b_content-area">
\t \t <main id="b_main" class="b_site__main" role="main">
\t \t <?php while (have_posts()) : the_post(); ?>
<!-- START product information -->
<div class="toptext">If you have any enquiries, please click here to contact us.</div>
<div class="toptext">Please ensure you include all the products information that you wish to enquire about.</div>
<div class="tableproduct">
<table>
<tr>
<th><div class="tabletitle">PRODUCT NAME</div></th>
<th><div class="tableresult"><?php wp_title(); ?></div></th>
</tr>
<tr>
<td><div class="tabletitle">PRODUCT DESCRIPTION</div></td>
<td><div class="tableresult"><?php the_field('product_description'); ?></div></td>
</tr>
<tr>
<td><div class="tabletitle">BRAND</div></td>
<td><div class="tableresult"><?php the_field('brand'); ?></div></td>
</tr>
<tr>
<td><div class="tabletitle">BARCODE</div></td>
<td><div class="tableresult"><?php the_field('barcode'); ?></div></td>
</tr>
<tr>
<td><div class="tabletitle">Ingredients (INCI Name)<br><div class="tablesubtitle">NOTE: Ingredients are listed in decreasing order of quantity.</div></div></td>
<td><div class="tableresult">
\t \t <?php
// check if the repeater field has rows of data
if(have_rows('ingredients-INCI')):
\t // loop through the rows of data
while (have_rows('ingredients-INCI')) : the_row();
// display a sub field value
the_sub_field('ingredients-INCI-group');
endwhile;
else :
// no rows found
endif;
?>
</div></td>
</tr>
<tr>
<td><div class="tabletitle">Fragrance Ingredients (INCI Name)<br><div class="tablesubtitle">NOTE: Fragrance Ingredients are those which require listing under EC648/2004 on detergents.</div></div></td>
<td><div class="tableresult">
\t \t
\t \t RESULTS HERE
\t \t
</div></td>
</tr>
</table>
<div class="tabletitleother">OTHER INFORMATION</div>
<div class="tableotherresults">The above formulation is for products manufactured between <?php the_field('date_from'); ?> and <?php the_field('date_to'); ?></div>
<div class="tableyellow">INCI/CAS/Ingredient information CLICK HERE or HERE</div>
</div>
<!-- END product information -->
\t \t <?php endwhile; // End of the loop. ?>
\t \t </main><!-- #b_main -->
\t </div><!-- #b_primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
此代码似乎打破输出。请帮忙!
答
你可以试试这个。
$productField = get_field('ingredients-INCI');
所有的中继器文件都会列在这个“$ productField”valriable中。
foreach($productField as $product){
echo $product['ingredients-INCI-group'];
}
我试过这个,但它并没有通过任何东西。 – Ashley
你必须在循环中显示你的内容。在这个变量中的“$ productField”,你将获得“ingredients-INCI”这个字段的所有值。我已经更新了我的答案,请检查 – Dinesh
我试过了你的建议,但没有多少运气。我应该在我的第一篇文章中加入'成分-INCI-group'是从一种称为'成分'的定制分类学中引入的。如果我将该子字段转换为标准文本字段,则会通过内容拉取内容,但是当我将其从其自定义分类标准中拉回时拉回。 – Ashley