Comment modifier l'ordre des publications dans Admin?
2 réponses
- votes
-
- 2012-09-27
Si vousne souhaitezpastoujours cliquer sur la colonne "Titre"pourtrier vos articlespartitre,vouspouvezplacer ce code dans lefichier
functions.php
de votrethème WordPress actuellement actif,ou dans unplugin. Celatrieratoujours automatiquement vosmessagespour vous,vousn'avez doncpas à cliquer sur la colonnetitre à chaquefois.Vouspouvez l'utiliserpour définir l'ordre detripar défaut destypes depublication.
/* Sort posts in wp_list_table by column in ascending or descending order. */ function custom_post_order($query){ /* Set post types. _builtin => true returns WordPress default post types. _builtin => false returns custom registered post types. */ $post_types = get_post_types(array('_builtin' => true), 'names'); /* The current post type. */ $post_type = $query->get('post_type'); /* Check post types. */ if(in_array($post_type, $post_types)){ /* Post Column: e.g. title */ if($query->get('orderby') == ''){ $query->set('orderby', 'title'); } /* Post Order: ASC / DESC */ if($query->get('order') == ''){ $query->set('order', 'ASC'); } } } if(is_admin()){ add_action('pre_get_posts', 'custom_post_order'); }
Vouspouvez utiliser certaines de ces conditions d'exemple ...
/* Effects all post types in the array. */ if(in_array($post_type, $post_types)){ } /* Effects only a specific post type in the array of post types. */ if(in_array($post_type, $post_types) && $post_type == 'your_post_type_name'){ } /* Effects all post types in the array of post types, except a specific post type. */ if(in_array($post_type, $post_types) && $post_type != 'your_post_type_name'){ }
Si vous vouliez appliquer cetri à TOUS lestypes d'articles,qu'ils soient ounon "intégrés" ...
Modifiez ceci:
$post_types = get_post_types(array('_builtin' => true), 'names');
À ceci:
$post_types = get_post_types('', 'names');
If you don't wish to always click the "Title" column to sort your posts by title, you can place this code in either your currently active WordPress theme's
functions.php
file, or within a plugin. This will automatically always sort your posts for you, so you don't have to click the title column every time.You can use this for setting default sort order on post types.
/* Sort posts in wp_list_table by column in ascending or descending order. */ function custom_post_order($query){ /* Set post types. _builtin => true returns WordPress default post types. _builtin => false returns custom registered post types. */ $post_types = get_post_types(array('_builtin' => true), 'names'); /* The current post type. */ $post_type = $query->get('post_type'); /* Check post types. */ if(in_array($post_type, $post_types)){ /* Post Column: e.g. title */ if($query->get('orderby') == ''){ $query->set('orderby', 'title'); } /* Post Order: ASC / DESC */ if($query->get('order') == ''){ $query->set('order', 'ASC'); } } } if(is_admin()){ add_action('pre_get_posts', 'custom_post_order'); }
You can use some of these example conditions...
/* Effects all post types in the array. */ if(in_array($post_type, $post_types)){ } /* Effects only a specific post type in the array of post types. */ if(in_array($post_type, $post_types) && $post_type == 'your_post_type_name'){ } /* Effects all post types in the array of post types, except a specific post type. */ if(in_array($post_type, $post_types) && $post_type != 'your_post_type_name'){ }
If you wanted to apply this sorting on ALL post types, regardless of whether or not they are "built-in"...
Change this:
$post_types = get_post_types(array('_builtin' => true), 'names');
To this:
$post_types = get_post_types('', 'names');
-
Est-il acceptable d'utiliser dans lafonctionplutôt que de vérifier avant l'action `if (! Is_admin) { revenir; } `Is it ok to use within the function rather than check before the action `if ( ! is_admin ) { return; }`
- 0
- 2012-09-30
- urok93
-
Je suppose que vouspouvez lefaire.I suppose you could do that.
- 0
- 2012-10-01
- Michael Ecklund
-
Vous devez ajouter un "return $ query;"avant lafin de lafonction,sinon celane fonctionnerapas dans les éditions wordpress ultérieures.You must add a "return $query;" before function end, otherwise this will not work in later wordpress editions.
- 0
- 2017-04-20
- Jobst
-
Jepense qu'unpluginexécute cettefonctionet remplacemafonctionpersonnalisée.Existe-t-il un hookpour s'assurer quemon codeestexécutéplutôt que lesplugins?I think a plugin is running this function and overriding my custom function. Is there a hook to ensure that my code is run rather than the plugins?
- 0
- 2018-08-20
- Thomas_Hoadley
-
- 2012-09-27
Ah,cliquez sur cepetit truc detitrepourbasculer letri alphabétique ....
Ah, click that little title thingy to toggle alphabetical sorting....
Commentpuis-je changer l'ordre des articles dans letableau debord d'administration,afin qu'ils s'affichentpar ordre alphabétiqueen fonction dutitre,plutôt que du dernieren premier?