我的代码如下,但返回的列表不按字母顺序排序。
任何帮助?
<?php
$termID = 4;
$taxonomyName = "location";
$termchildren = get_term_children( $termID, $taxonomyName );
echo '<ul class="list">';
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomyName );
echo '<li><span class="feature"><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
?>
答案 0 :(得分:4)
使用此:
$termID = 4;
$taxonomyName = "location";
$termchildren = get_term_children( $termID, $taxonomyName );
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomyName );
$namearray[$term->name]= get_term_link( $term->name, $taxonomyName );
}
print_r($namearray);
ksort($namearray);
echo '<ul class="list">';
foreach ($namearray as $key => $value) {
echo '<li><span class="feature"><a href="'.$value.'">' . $key . '</a></li>';
}
echo '</ul>';