高级自定义字段产品类别中的中继器(woocommerce)
问题描述:
我目前使用ACF 5.我已经在产品类别上设置了中继器。高级自定义字段产品类别中的中继器(woocommerce)
我目前正在努力如何让它输出信息。我是acrhive产品循环内,并且我更新了以下模板包含被输出内容:
<?php while (have_posts()) : the_post(); ?>
<?php wc_get_template_part('content', 'product_cat'); ?>
<?php endwhile; // end of the loop. ?>
在内容product_cat.php我已在每个循环的中继以下。所有的基本信息已经显示出来了,标题,woocommerce分类图像等等。它是我添加到类别本身的中继器,我无法展示。
<?php
$terms = get_field('attributes', 'product_cat_'.$term->term_id);
if($terms): ?>
<ul>
<?php foreach($terms as $term): ?>
<li>
<?php the_sub_field('attribute'); ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
任何想法,将不胜感激
答
打印出来ARGS第一:
<?php print_r($category);?>
然后利用其输出端产生如下:
<?php
$cat_id = $category->term_id; //used below to get a the acf from the categories!
?>
<?php
// $cat_id = $category->term_id;
$terms_features = get_field('features', 'product_cat_'.$cat_id);
if($terms_features):
// print_r($terms_features);
?>
<ul>
<?php foreach($terms_features as $terms_feature):
// print_r($term);
?>
<?php
$image_icon = $terms_feature['icon'];
$image_icon_show = $image_icon[sizes][large];
// print_r($image_feature);
?>
<li>
<img src="<?php echo $image_icon_show;?>" />
<?php echo $terms_feature['description'];?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
你有'WP_DEBUG '启用?你可能想要。至少,如果你有未定义的对象/变量,这可能会告诉你。你如何定义'$ term-> term_id'?我会从那里开始,因为如果没有'term',你甚至不会进入'foreach()'循环。之后,我对ACF了解不够。 – helgatheviking 2014-12-06 11:53:34