Ajouter une colonne personnalisée à l'aperçu du type de message personnalisé dans le backend
-
-
ok,je viens detrouver ce lien: http://www.deluxeblogtips.com/add-custom-column/MAIS commentpuis-je rendre la colonnetriable?okay, i just found this link: http://www.deluxeblogtips.com/add-custom-column/ BUT how can i make the column sortable?
- 0
- 2017-01-23
- beta
-
3 réponses
- votes
-
- 2017-01-23
D'accord,j'aitrouvé une réponsemoi-même.Pour aider lesgens qui liront ceci à l'avenir,voici ce quej'aifait:
1) Celaexplique comment ajouter une colonne: http://www.deluxeblogtips.com/add-custom-column/
2) Ceciexplique comment ajouter une colonnetriable: https://wordpress.org/support/topic/admin-column-sorting/
Okay, I found an answer myself. To help people who will read this in future, this is what I did:
1) This explains how to add a column: http://www.deluxeblogtips.com/add-custom-column/
2) This explains how to add a sortable column: https://wordpress.org/support/topic/admin-column-sorting/
-
- 2017-10-10
Les hookspour créer des colonnespersonnaliséeset leurs données associéespour untype depublicationpersonnalisé sont respectivementmanage _ {$post_type} _posts_columnset manage _ {$post_type} _posts_custom_column,où {$post_type}est lenom dutype depublicationpersonnalisé.
Cetexemple de la documentation supprime la colonne auteuret ajoute unetaxonomieet une colonne demétadonnées:
// Add the custom columns to the book post type: add_filter( 'manage_book_posts_columns', 'set_custom_edit_book_columns' ); function set_custom_edit_book_columns($columns) { unset( $columns['author'] ); $columns['book_author'] = __( 'Author', 'your_text_domain' ); $columns['publisher'] = __( 'Publisher', 'your_text_domain' ); return $columns; } // Add the data to the custom columns for the book post type: add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 ); function custom_book_column( $column, $post_id ) { switch ( $column ) { case 'book_author' : $terms = get_the_term_list( $post_id , 'book_author' , '' , ',' , '' ); if ( is_string( $terms ) ) echo $terms; else _e( 'Unable to get author(s)', 'your_text_domain' ); break; case 'publisher' : echo get_post_meta( $post_id , 'publisher' , true ); break; } }
Copié àpartir d'ansexistants.
The hooks to create custom columns and their associated data for a custom post type are manage_{$post_type}_posts_columns and manage_{$post_type}_posts_custom_column respectively, where {$post_type} is the name of the custom post type.
This example from the documentation removes the author column and adds a taxonomy and meta data column:
// Add the custom columns to the book post type: add_filter( 'manage_book_posts_columns', 'set_custom_edit_book_columns' ); function set_custom_edit_book_columns($columns) { unset( $columns['author'] ); $columns['book_author'] = __( 'Author', 'your_text_domain' ); $columns['publisher'] = __( 'Publisher', 'your_text_domain' ); return $columns; } // Add the data to the custom columns for the book post type: add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 ); function custom_book_column( $column, $post_id ) { switch ( $column ) { case 'book_author' : $terms = get_the_term_list( $post_id , 'book_author' , '' , ',' , '' ); if ( is_string( $terms ) ) echo $terms; else _e( 'Unable to get author(s)', 'your_text_domain' ); break; case 'publisher' : echo get_post_meta( $post_id , 'publisher' , true ); break; } }
Copied from existing ans.
-
la colonneest-elletriable?is the column sortable?
- 0
- 2017-10-10
- beta
-
non,ces colonnesne serontpastriables .. vous devez les rendretriables ..no these colums won't be sortable..you have to make it sortable..
- 0
- 2017-10-11
- Pravin Work
-
- 2017-10-10
Voici le code completpour cela:
add_filter('manage_edit-video_columns', 'my_columns'); function my_columns($columns) { $columns['eventDate'] = 'Event Date'; return $columns; } add_action('manage_posts_custom_column', 'my_show_columns'); function my_show_columns($name) { global $post; switch ($name) { case 'eventDate': $eventDate = get_post_meta($post->ID, 'eventDate', true); echo $eventDate; } } add_filter( 'manage_edit-video_sortable_columns', 'my_sortable_date_column' ); function my_sortable_date_column( $columns ) { $columns['eventDate'] = 'Event Date'; return $columns; }
Merci
Here is the entire code for this:
add_filter('manage_edit-video_columns', 'my_columns'); function my_columns($columns) { $columns['eventDate'] = 'Event Date'; return $columns; } add_action('manage_posts_custom_column', 'my_show_columns'); function my_show_columns($name) { global $post; switch ($name) { case 'eventDate': $eventDate = get_post_meta($post->ID, 'eventDate', true); echo $eventDate; } } add_filter( 'manage_edit-video_sortable_columns', 'my_sortable_date_column' ); function my_sortable_date_column( $columns ) { $columns['eventDate'] = 'Event Date'; return $columns; }
Thanks
J'ai untype demessagepersonnalisé appelé événements .Dans lebackend/administration,je peux listertous cestypes d'articlespersonnalisés,c'est-à-dire les événements :
Comme vouspouvez le constater,cet aperçu comportetrois colonnes: Titre , Balises et Date .Chacun de ces événements possède un champpersonnalisénommé eventDate .
Ma questionestmaintenant la suivante: commentpuis-je ajouter une colonnetriable eventDate à l'aperçu des événements (photo ci-dessus)?