0

私が使用しているテンプレートはthe_category()、投稿が属するカテゴリをリストするために呼び出しています。それらを名前順に並べています。ID カテゴリの順序を逆にする方法はありますか?

4

2 に答える 2

4

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 
    }

次のいずれかのorderby値を使用できます

id
name - default
slug
count
term_group
于 2012-04-22T23:12:58.757 に答える
0

現在、the_category は機能別に並べ替えられていません。wp-includes/category-template.phpに移動する必要があります そのファイルには「get_the_terms」という関数があります.この関数には次のような行があります$terms = wp_get_object_terms( $id, $taxonomy );

wp_get_object_terms は、args に追加の引数を取ることができます。以下のようにここで編集できます。

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

必要に応じて $args を変更できます

お役に立てれば

于 2012-04-22T21:01:11.767 に答える