我想知道如何在此类别数组上使用一些类别自定义字段,使用当前代码,仅打印类别术语。
<?php
$terms = get_terms('productcat');
foreach ($terms as $key => $term) {
$link = get_term_link($term);
$cat_ttl =the_field('cat_ttl');
$cat_img =the_field('featured_image');
echo '<li>
<a href="'.$link.'">
<div class="imager"><img src="'.$cat_ttl.'" alt="商品"></div>
<div class="right">
<h3>'.$cat_ttl.'</h3>
<p class="det">'.$term->slug.'</p>
</div>
</a>
</li>';
}
?>
答案 0 :(得分:0)
我找到了正确的语法:
<?php
$terms = get_terms('productcat');
foreach ($terms as $key => $term) {
$link = get_term_link($term);
$image = get_field('featured_image', $term);
$cat_ttl =get_field('cat_ttl', $term);
echo '<li>
<a href="'.$link.'">
<div class="imager"><img src="'.$image.'" alt="商品"></div>
<div class="right">
<h3>'.$cat_ttl.'</h3>
<p class="det">'.$term->slug.'</p>
</div>
</a>
</li>';
}
?>