2012-04-22 53 views

回答

0

當前the_category沒有按功能排序。你需要去WP-包括/品類的template.php在file.In有一個名爲「get_the_terms」功能,此功能有像$terms = wp_get_object_terms($id, $taxonomy);

wp_get_object_terms可以採取args.You額外的參數可以在這裏編輯下圖;

$args = array('orderby' => 'id', 'order' => 'ASC'); 
$terms = wp_get_object_terms($id, $taxonomy, $args); 

您可以修改的$ args根據您的需要

希望這有助於

+0

非常感謝你!!!!! – 2012-04-22 21:29:23

+0

現在有效嗎? – 2012-04-23 11:55:54

3

只需更換您的the_category(' ')這個

$cats=get_the_category(); 
$cid=array(); 
foreach($cats as $cat) { $cid[]=$cat->cat_ID; } 
    $cid=implode(',', $cid); 
    foreach((get_categories('orderby=name&include='.$cid)) as $category) { // notice orderby 
     echo '<a href="'.get_category_link($category->cat_ID).'">'.$category->cat_name.'</a> '; // keep a space after </a> as seperator 
    } 

您可以使用排序依據值的一個以下

id 
name - default 
slug 
count 
term_group 
+0

感謝您的代碼。我試圖讓類別先打印出父類別,然後再打印出子類別。我嘗試了term_group的命令,它似乎工作。這是如何讓它做我想做的事?在搜索互聯網時,我發現有些人說不要使用term_group,也不會說term_group實際上是什麼。 – kosher 2017-05-30 18:38:20