1

我的代码如下,但是返回的列表没有按字母顺序排序。

有什么帮助吗?

<?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>';
?> 
4

1 回答 1

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>';
于 2012-11-22T14:13:56.167 回答