Modifier l'ordre de la liste de taxonomie personnalisée
-
-
Vous voulez direentrer la commande sur unebaseparposte?You mean entering order on a per post base?
- 0
- 2011-01-21
- hakre
-
Peut-être commanderparidentifiant?Maybe order by id?
- 0
- 2011-01-21
- Bainternet
-
Mieuxje peux dire qu'ils sont affichés dans l'ordre alphabétique,doncje ne comprendsprobablementpas la question.Où voulez-vousexactement cela?Pouvez-vous donner une capture d'écranet unexemple d'URL où voustrouverez ce que vous voulez changer?Best I can tell they are displayed in alphabetic order, so I'm probably not understanding the question. Where exactly do you want this? Can you give a screenshot and an example URL where you'll find what you want changed?
- 0
- 2011-01-22
- MikeSchinkel
-
5 réponses
- votes
-
- 2011-01-27
Cen'estpaspossible "prêt à l'emploi" ...
Les optionspar défaut «orderby» sont (croissant ou décroissant)
- Nom de l'ID
- Par défaut
- limace
- compter
- term_group
Tout celaest détaillé dans le codex.
-
Cela dit,il y a des damesintelligentes & amp;messieursici.Si quelqu'unpeut le résoudre,l'un de cesgarspeutj'en suis sûr!
This isn't possible "out of the box"...
The default 'orderby' options are (ascending or descending)
- ID name
- Default
- slug
- count
- term_group
These are all detailed in the codex.
--
That said there are some clever ladies & gents here. If anyone can solve it, one of these guys can i'm sure!
-
- 2012-02-21
Aprèspasmal de rechercheset detests approfondis,j'aitrouvé la réponse.
Ajoutez ce code aufunctions.php de votrethème:
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');
(Crédit: ceciestbasé sur -mais amélioré - http://wordpress.kdari.net/2011/07/listing-tags-in-custom-order.html )
After quite a bit of searching and extensive tests, I found the answer.
Add this code to your theme's 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');
(Credit: this is based on - but improved - http://wordpress.kdari.net/2011/07/listing-tags-in-custom-order.html)
-
Celafonctionne-t-ilmême si l'administrateurefface son cache?Sembleprécaire de dépendre du cachepour l'ordre destermes.Does this work even if the admin clears their cache? Seems precarious to depend on cache for term order.
- 0
- 2016-12-07
- PBwebD
-
Si l'administrateurefface son cache,lesnouveauxtermes seront supprimés detoutefaçon carilsne sontpasencoreenregistrés.Nous utilisons le code ci-dessus sur denombreux sites Wordpress depuis quej'aipublié ceciet jen'aijamais rencontré deproblème.If the admin clears their cache, then the new terms will be gone anyway because they're not saved yet. We've been using the above code on many Wordpress sites since I posted this and I've never ran into a problem.
- 1
- 2016-12-07
- Biranit Goren
-
@BiranitGorenme pardonne de reprendre ce sujet,mais lapréoccupation centrale danstoutes les réponsesest que `term_order`n'estpas supporténativement.Donc,je me demande,dans votreexemple de code,oùest défini `term_order`pour que vouspuissieztrier dessus?@BiranitGoren pardon me for resuming this topic, but the centeral concern in all the answers is that `term_order` is not natively supported. So I'm wondering, in your code example, where is `term_order` defined so that you can sort on it?
- 1
- 2019-06-11
- GigiSan
-
@GigiSanil ESTen fait supporténativement,mais simplementinutilisé.Wordpress aterm_order dans sonnoyau -maisne l'utilisepaspar défaut.Par conséquent,vousn'avezpasbesoin de le définir,ilest déjà défini.(Voir ceci surtrac: https://core.trac.wordpress.org/ticket/9547)@GigiSan it IS actually natively supported, but simply unused. Wordpress has term_order in its core - but does not make use of it by default. Therefore, you do not need to define it, it is already defined. (See this on trac: https://core.trac.wordpress.org/ticket/9547)
- 2
- 2019-07-14
- Biranit Goren
-
- 2012-07-31
J'aieu dumal àtrouver la réponse auxtermesenfants alphabétiques d'unetaxonomiepersonnalisée ... Jene recommanderaispas demodifier lesfichiers WP debase,alors voici ce quej'ai ajouté àmonfichiertaxonomy.phppour lister les descriptions detaxonomiepersonnalisées,avec des liens vers lestermesenfantspar ordre alphabétique. Modifiezen fonction de vosbesoins,j'espère que cela aidera quelqu'un là-bas.
// 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="' . get_term_link( $term->name, $termTaxonomy ) . '" alt="' .$term->description. '">' . $term->name . '</a></li>'; } echo '</ul>';
I've been struggling to find the answer to alphabetical child terms of a custom taxonomy ... I wouldn't recommend altering core WP files, so here's what I added to my taxonomy.php file to list out custom taxonomy descriptions, with links to child terms in alphabetical order. Modify to suit your needs, I hope this helps someone out there.
// 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="' . get_term_link( $term->name, $termTaxonomy ) . '" alt="' .$term->description. '">' . $term->name . '</a></li>'; } echo '</ul>';
-
- 2017-09-11
Je sais que c'est une sorte detriche,mais vouspouveztoujours utiliser la Simple CustomPlug-in Post Order .C'estgratuitet cela vouspermet detrier lestaxonomiesen plus destypes depublication.
I know this is kind of cheating, but you could always use the Simple Custom Post Order plugin. It's free, and it allows you to sort Taxonomies in addition to Post Types.
-
- 2019-12-12
Et aprèspour afficher dans lapage Web lebon ordre celapourrait être:
pourmettre "orderby"=> "term_group" dans vos wp_get_post_terms
Exemple:
"poste"est lenom demataxonomiepersonnalisée,mettez le vôtre
$poste = wp_get_post_terms($post->ID, 'poste', array("fields" => "names", "orderby" => "term_group")); if(!empty($poste[0])){ echo $poste[0];} if(!empty($poste[1])){ echo " - ", $poste[1]; }
And after to display in web page the good order it could be :
to put "orderby" => "term_group" in your wp_get_post_terms
Example :
"poste" is my custom taxonomy name, put yours
$poste = wp_get_post_terms($post->ID, 'poste', array("fields" => "names", "orderby" => "term_group")); if(!empty($poste[0])){ echo $poste[0];} if(!empty($poste[1])){ echo " - ", $poste[1]; }
Par défaut,WordPress classe lestaxonomiespersonnalisées (sousforme debalises dans ce cas)par ordre alphabétiqueet nonpar ordre de saisie dans la zone debalise.
Quelqu'un a-t-il connaissance d'unmoyen d'afficher lestaxonomiespersonnalisées dans l'ordre dans lequelelles ont étéentrées dans l'écran demodification depublication?
L'urlen questionest: http://granadatheater.com/
Les artistes de GGW (Goes Good With) sont actuellement classéspar ordre alphabétiqueet ils veulent que cela changepour qu'ils soient classés de lamêmemanière qu'ils ont été saisis.
Donc,si vous saisissez Artist1,Artist3,Artist2,c'est comme ça qu'il devrait apparaître sur lefrontend du site.