2016-11-17 81 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);