<?php $terms = wp_get_post_terms($post->ID,'category');
foreach ($terms as $term) {
$termcomp = $term->taxonomy . '_' . $term->term_id; } ?>
<?php the_field('tagline' , $termcomp); ?>
如何在wordpress上使用此代码而不会回显6次,因为我在该类别中有6个帖子..
整页模板在那里,foreach也在底部,这个工作正常,只需要输出一次。
答案 0 :(得分:0)
使用高级自定义字段,您可以使用get_field('field', 'category_'.$cat_id)
或the_field()
获取类别分类自定义字段的字段,如果您想自动回显结果。在您的情况下,您首先需要确定当前的类别ID,然后使用它来the_field()
为您想要的字段名称tagline
。这应该在Loop
:
// only show on category pages
if(is_category()){
global $wp_query;
// get category id from query variables
$cat_ID = get_query_var('cat');
the_field('tagline', 'category_'.$cat_ID);
}