問題描述

什麼功能會顯示自定義分類與文章相關的文章?

我目前正在使用 get_the_term_list,它對單個頁面非常有用,但在 archive-postype.php 固定連結標題標籤中使用分類法則不太好。

最佳解決方案

wp_get_object_terms() 返回與物件相關聯的術語 (例如,一個帖子或頁面或自定義帖子) 作為文字 (通常在陣列中) 。

來自 the Codex page for wp_get_object_terms()

$productcategories = wp_get_object_terms($post->ID, 'productcategories');

次佳解決方案

但是 @anu 是對的,我想出你可以呼叫 php 函式 strip_tags 去除返回值的標籤。

$terms = get_the_term_list( $post->ID, 'tags' );
$terms = strip_tags( $terms );

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。