diff --git a/elementor-category-grid-widget.php b/elementor-category-grid-widget.php index 3c2b0b5..b77cf1e 100644 --- a/elementor-category-grid-widget.php +++ b/elementor-category-grid-widget.php @@ -52,6 +52,40 @@ function ccgw_enqueue_media_uploader( $hook_suffix ) { } add_action( 'admin_enqueue_scripts', 'ccgw_enqueue_media_uploader' ); +// 1) Déclarez la colonne "Image" dans le tableau des catégories +add_filter( 'manage_edit-category_columns', function( $columns ) { + $new = []; + foreach ( $columns as $key => $label ) { + $new[ $key ] = $label; + if ( 'name' === $key ) { + // après la colonne "Nom", on insère notre colonne "Image" + $new['category_image'] = esc_html__( 'Image', 'category-grid-widget' ); + } + } + return $new; +} ); + +// 2) Remplissez la colonne "Image" +add_filter( 'manage_category_custom_column', function( $out, $column, $term_id ) { + if ( 'category_image' === $column ) { + $thumb_id = get_term_meta( $term_id, 'thumbnail_id', true ); + if ( $thumb_id ) { + // Affiche la version 'thumbnail' de l'image + return wp_get_attachment_image( $thumb_id, 'thumbnail', false, [ + 'style' => 'max-width:60px;height:auto;' + ] ); + } + } + return $out; +}, 10, 3 ); + +// 3) Un peu de CSS pour la largeur de colonne et la mise en forme +add_action( 'admin_head-edit-tags.php', function() { + echo ''; +} ); /** * Affiche le champ d'upload dans le formulaire de création de catégorie.