問題描述
默認情況下,WordPress 按字母順序排序自定義分類法 (作為標籤),而不是按照在標籤框中輸入的順序。
有人知道有什麼方法可以按照他們在帖子編輯屏幕中輸入的順序顯示自定義分類標準?
該網址是:http://granadatheater.com/
GGW(Goes Good With) 藝術家目前是按字母順序排列的,他們希望改變它們,這樣它們的輸入方式與輸入方式相同。
所以如果輸入它的 Artist1,Artist3,Artist2 這是如何應該出現在網站的前端。
最佳解決方案
這是不可能的 「開箱即用」…
默認的’orderby’ 選項是 (升序或降序)
-
ID 名稱
-
默認
-
金屬塊
-
計數
-
term_group
這些都在 codex 中詳細説明。
–
那就是説有一些聰明的女士們紳士在這裏如果有人能解決這個問題,我可以確定這些人中的一個
次佳解決方案
經過相當多的搜索和廣泛的測試,我找到了答案。
將此代碼添加到主題的 functions.php 中:
function set_the_terms_in_order ( $terms, $id, $taxonomy ) {
$terms = wp_cache_get( $id, "{$taxonomy}_relationships_sorted" );
if ( false === $terms ) {
$terms = wp_get_object_terms( $id, $taxonomy, array( 'orderby' => 'term_order' ) );
wp_cache_add($id, $terms, $taxonomy . '_relationships_sorted');
}
return $terms;
}
add_filter( 'get_the_terms', 'set_the_terms_in_order' , 10, 4 );
function do_the_terms_in_order () {
global $wp_taxonomies; //fixed missing semicolon
// the following relates to tags, but you can add more lines like this for any taxonomy
$wp_taxonomies['post_tag']->sort = true;
$wp_taxonomies['post_tag']->args = array( 'orderby' => 'term_order' );
}
add_action( 'init', 'do_the_terms_in_order');
(信用:這是基於 – 但改進 – http://wordpress.kdari.net/2011/07/listing-tags-in-custom-order.html)
第三種解決方案
我一直在努力尋找一個自定義分類法的字母子句的答案… 我不建議改變核心 WP 文件,所以這裏是我添加到我的 taxonomy.php 文件列出自定義分類法描述,鏈接以字母順序排列為小孩。修改以滿足您的需要,我希望這有助於某人在那裏。
// Get Main Taxonomy for use in template file
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$termTaxonomy = $term->taxonomy;
<h1><?php echo apply_filters( 'the_title', $term->name ); ?></h1>
<?php // test for description before unleashing a div
if ( !empty( $term->description ) ):
echo '<div class="description">';
echo $term->description;
echo '</div>;
endif; ?>
// Now get children terms, using get_term & 'child_of' get's us alphabetical order
$termchildren = get_terms( $termTaxonomy, array(
'child_of' => $term->term_id,
'hierarchical' => 0,
'fields' => 'ids',
'hide_empty' => 0
) );
// Make an alphabetical linked list
echo '<ul>';
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $termTaxonomy );
// Modify this echo to customize the output for each child term
echo '<li><a href="http://'%20.%20get_term_link(%20$term->name,%20$termTaxonomy%20)%20.%20'" alt="' .$term->description. '">' . $term->name . '</a></li>';
}
echo '</ul>';
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。