Comment créer un tri personnalisé pour les catégories WordPress
-
-
Cet articlepourrait aider http://www.wphub.com/sorting-categories-custom-sort-order/This post might help http://www.wphub.com/sorting-categories-custom-sort-order/
- 0
- 2013-08-07
- Srikanth AD
-
Mercipour ce lien.Je l'ai regardémais celame semble êtrebeaucoup detravailet jene veuxpas vraiment utiliser depluginnonplus.Maisje vous remerciebeaucoup d'avoir répondu si rapidement.Je suis vraiment reconnaissant dutemps que vous avezprispouressayer d'aider.Thank you for that link. I looked at it but it seems like a lot of work and I don't want to really use a plugin either. But I thank you very much for responding so quickly. I am really grateful for the time you took to try and help.
- 0
- 2013-08-07
- Wayne Hatter Jr.
-
[Celapourrait aider] (http://quickhow.net/2012/code/how-to-get-posts-using-post-ids-in-the-order-it-was-given-on-wordpress).Bien que ce soitpour lespublications,la deuxième solutionpourrait vous être utile carelle utilisephpet array.[This might help](http://quickhow.net/2012/code/how-to-get-posts-using-post-ids-in-the-order-it-was-given-on-wordpress). Although it's for posts but the second solution could be useful for you as it is using php and array.
- 0
- 2013-08-07
- Sisir
-
3 réponses
- votes
-
- 2014-01-03
Si vous utilisez déjà Champspersonnalisés avancés (ce que vous devriez être!),vouspouvez créer une commande.champpour vos catégories àpartir duquel vouspouvez les définirmanuellement dans l'ordrenumérique.
Ilne vous resteplus qu'à:
$categories = get_categories( $args ); usort($categories, function($a, $b) { return get_field("category_order", "category_".$a->term_id) - get_field("category_order", "category_".$b->term_id); }); foreach ($categories as $category){ ...
Où
category_order
est lenom du champ que vous avez créé avec ACF.Remarque: Utilisation de laméthode d'utilisation de PHP 5.3.
If you're already using Advanced Custom Fields (which you should be!) you can create an order field for your categories from which you can set them manually in numerical order.
Then all you have to do is:
$categories = get_categories( $args ); usort($categories, function($a, $b) { return get_field("category_order", "category_".$a->term_id) - get_field("category_order", "category_".$b->term_id); }); foreach ($categories as $category){ ...
Where
category_order
is the field name you created with ACF.Note: Using the PHP 5.3 way of usort.
-
- 2013-08-07
D'accord,j'aitrouvé ceplugin quifaitexactement ce queje veux.Jene voulaispas utiliser depluginmais celui-ci semblait assez légeret ilfaisaitparfaitement l'affaire. http://wordpress.org/plugins/taxonomy-terms-order/
Okay, I found this plugin that does exactly what I want. I didn't want to use a plugin but this one seemed pretty light weight and it did the job perfectly. http://wordpress.org/plugins/taxonomy-terms-order/
-
- 2019-10-18
Le code d'originefonctionnera si vous changez les argumentsen:
'orderby' => 'include'
$args = array( 'orderby' => 'include', 'order' => 'ASC', 'include' => '5,6,7,8,29,9,10,11,12,13,14,15,16' ); $categories = get_categories($args); foreach($categories as $category) { echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name . '</a>' . ' ' . '(' . $category->count . ')' . '</li> '; }
The original code will work if you change the arguments to:
'orderby' => 'include'
$args = array( 'orderby' => 'include', 'order' => 'ASC', 'include' => '5,6,7,8,29,9,10,11,12,13,14,15,16' ); $categories = get_categories($args); foreach($categories as $category) { echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name . '</a>' . ' ' . '(' . $category->count . ')' . '</li> '; }
-
ouais,çamarchepourmoi :)yup, that works for me :)
- 0
- 2020-08-05
- Nuno Sarmento
J'ai ceproblème queje rencontre. J'essaie detriermes catégoriespour les afficher dans l'ordre queje souhaite. J'ai lu la documentation WordPress surtoutes les options detri. Cependant,iln'y a aucuneinclination sur lafaçon de choisir les catégorieset de lesfaire couler commeje le souhaite.
Voici ce que le Codexprésente:
Cependant,commeje l'ai dit,celane m'aidepas carj'en aibesoinpour les afficher dans l'ordre queje choisis.
Voici le code quej'implémenteen cemoment. C'est dans l'ordre queje souhaite qu'ils s'affichent.