从一系列ID获取儿童条款?

时间:2012-11-21 17:07:02

标签: php wordpress taxonomy

我正在使用此代码发布名为“location”

的分类法的所有子项的列表
<?php
$termID = 10;
$taxonomyName = "location";
$termchildren = get_term_children( $termID, $taxonomyName );

echo '<ul>';
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomyName );
echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
?> 

目前,代码正在使用术语ID 10并获取子项并显示在列表中。

但是我想添加多个术语ID并显示我添加的id的所有子项的列表。

我的身份证是4,6,8,10,14,18,22

寻找一些帮助来弄清楚如何做到这一点?

干杯

1 个答案:

答案 0 :(得分:0)

我找到了自己问题的答案。使用get_terms将使所有条款都退回,因此无需指定我的条款的个人ID。

我的代码是

<?php
$args = array( 'taxonomy' => 'location' );

$terms = get_terms('location', $args);

$count = count($terms); $i=0;
if ($count > 0) {
    $cape_list = '<p class="location-archive">';

    foreach ($terms as $term) {
        $i++;
        $term_list .= '<li><span class="feature"><a href="/location/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a></li>';
        if ($count != $i) $term_list .= ' &middot; '; else $term_list .= '</p>';
    }
    echo '<ul class="list">';
    echo $term_list;
    echo '</ul>';

}
?>
相关问题