我正在嘗試在 Wordpress 中創(chuàng)建分類法的鏈接,這樣當您單擊一個時,它會將您帶到 Wordpress 頁面,列出該分類法的所有帖子,但我不太明白。你會怎么做?當前代碼: <?php $post_type = get_post_type(get_the_ID()); $taxonomies = get_object_taxonomies($post_type); $taxonomy_names = wp_get_object_terms(get_the_ID(), $taxonomies, array("fields" => "names")); if(!empty($taxonomy_names)) : foreach($taxonomy_names as $tax_name) : ?> <h2 class="text-lg"><?php echo $tax_name; ?> </h2> //planning to have the link here (<a href="?">?</a>) <?php endforeach; endif; ?>感謝所有幫助!
1 回答

繁華開滿天機
TA貢獻1816條經(jīng)驗 獲得超4個贊
試試這個代碼,它在我這邊工作正常
<?php
$post_type = get_post_type(get_the_ID());
$taxonomies = get_object_taxonomies($post_type);
$taxonomy_names = wp_get_object_terms(get_the_ID(), $taxonomies);
if(!empty($taxonomy_names)) :
foreach($taxonomy_names as $tax_name) :
?>
<h2 class="text-lg"><?php echo $tax_name->name; ?> </h2>
<a href="<?php echo get_term_link($tax_name->term_id); ?>">texonomy link </a>
<?php
endforeach;
endif;
?>
- 1 回答
- 0 關(guān)注
- 123 瀏覽
添加回答
舉報
0/150
提交
取消