0
我想顯示一個自定義帖子類型的分類列表,不包括那些不是分層的列表。顯示分類列表,只有它們是分層的
下面的代碼目前的工作,但顯示所有的分類法,但我不能得到它來檢查分類是否分層次之前,通過循環運行它。
我知道有運行此檢查一個WordPress的功能,但由於我平時工作的前端,我似乎無法搞清楚在哪裏把它,以便使其生效:
is_taxonomy_hierarchical($taxonomy)
以下是我使用的輸出的分類列表功能:
// get taxonomies terms links
function custom_taxonomies_terms_links(){
// get post by post id
$post = get_post($post->ID);
// get post type by post
$post_type = $post->post_type;
// get post type taxonomies
$taxonomies = get_object_taxonomies($post_type, 'objects');
$out = array();
echo '<a href="';
echo '/';
echo '">';
echo 'Home';
echo "</a>/";
foreach ($taxonomies as $taxonomy_slug => $taxonomy){
// get the terms related to post
$terms = get_the_terms($post->ID, $taxonomy_slug);
if (!empty($terms)) {
foreach ($terms as $term) {
$out[] =
'<a href="'
. get_term_link($term->slug, $taxonomy_slug) .'">'
. $term->name
. "</a>/";
}
$out[] = " ";
}
}
return implode('', $out);
}
謝謝,這正是我所追求的。 有沒有什麼機會可以解釋你添加的語法,僅供將來參考? – Nervewax 2015-03-03 13:20:47
很高興工作。我添加了一些額外的信息。 – bobdye 2015-03-03 16:14:56