0
需要幫助:我必須只顯示自定義分類標準WordPress的特定父項的子項,在我的情況下:分類標準名稱:「region」,與此有關:父母條款及其子女: 歐洲: - 葡萄牙; - 德國; - 英格蘭;想要只顯示自定義分類標準的特定父項的子項WordPress
亞洲: - China;日本; - 日本;
因此,例如我需要在列表中只顯示歐洲的兒童,我該如何做到這一點?我試了很多方法,只能顯示所有父母的所有孩子:
<?php
$taxonomyName = "region";
//This gets top layer terms only. This is done by setting parent to 0.
$parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false));
echo '<ul>';
foreach ($parent_terms as $pterm) {
//Get the Child terms
$terms = get_terms($taxonomyName, array('parent' => $pterm->term_id, 'orderby' => 'slug', 'hide_empty' => false));
foreach ($terms as $term) {
echo '<li><a href="' . get_term_link($term) . '">' . $term->name . '</a></li>';
}
}
echo '</ul>';
?>
但我只需要顯示一個特定的父母。謝謝你的幫助