2016-11-17 31 views
0

enter image description here我必须添加多个类别链接在分类学领域

enter image description here

的WordPress在ACF。

我创建分类领域创造类别链接和标题 但它不会在前端显示。

有人请帮我找到一个解决方案。 这里是我的代码,但 它不工作:

<ul> 

<?php foreach($terms as $term): ?> 

<a href="<?php echo get_term_link($term); ?>">View all '<?php echo $term->name; ?>' posts</a> 

<?php endforeach; ?> 

</ul> 

回答

1

如何u盘$条款?

这是标记为分类学领域

<?php 

$terms = get_field('taxonomy_field_name'); 

if($terms): ?> 

    <ul> 

    <?php foreach($terms as $term): ?> 

     <h2><?php echo $term->name; ?></h2> 
     <p><?php echo $term->description; ?></p> 
     <a href="<?php echo get_term_link($term); ?>">View all '<?php echo $term->name; ?>' posts</a> 

    <?php endforeach; ?> 

    </ul> 

<?php endif; ?> 

如果不工作,你需要设置好这个字段存储的ID:

$terms = get_field('taxonomy_field_name', $post_id);