2013-08-05 40 views
0

這是一個非常新手的問題。但是,我將如何按字母順序排列結果,以便列表中的名稱是按順序排列的?PHP排序在Wordpress

<?php 
// FOR THE CATEGORIES (PRODUCT TYPE) 
$terms_one = get_terms('product_cat'); 
$count_one = count($terms_one); 
$i_one = 0; 

echo '<ul class="submenu one filter option-set" data-filter-group="gem-type">'; 
echo '<li><a href="javascript:void(0)" data-filter-value="" class="selected">ALL</a>'; 

if ($count_one > 0) {   
foreach ($terms_one as $term_one) 
{ 
    $i_one++;  
    $term_list_one .= '<li><a href="javascript:void(0)" data-filter-value=".'. $term_one->slug .'"> <span>'. $term_one->count .'</span>'. $term_one->name .'</a></li>'; 

    if ($count_one != $i_one) 
    { 
     $term_list_one .= ''; 
     } else { 
     $term_list_one .= ''; 
    } 
} 
    echo $term_list_one; 
} 
echo '</ul>'; 
?> 

回答

0

foreach循環之前嘗試

asort($terms_one); 

如果您希望通過陣列鍵排序可以使用ksort() ...

1
$terms_one = get_terms('product_cat','orderby=FIELD&order=ASC'); 

的更多信息,你可以參考這裏的文檔:http://codex.wordpress.org/Function_Reference/get_terms

+0

由於傑米。這就是我正在使用的。當它不起作用時,我想我一定是做錯了。我正在嘗試對http://jigoshop.com/類別進行排序。也許他們做了一些棘手的事情,不允許排序? –