web-dev-qa-db-fra.com

Personnaliser ma table de taxonomie personnalisée dans le panneau d'administration

J'ai enregistré une nouvelle taxonomie pour mon type de publication personnalisé et j'essaie maintenant de modifier la table de taxonomie.

J'ai supprimé avec succès la colonne de description mais je ne peux pas le comprendre comment modifier la largeur de la colonne pour la colonne indiquant le nombre de types d'articles personnalisés trouvés dans cette taxonomie particulière. La classe CSS de la colonne semble être column-posts et, par conséquent, sa largeur est définie sur 10%.

La classe CSS de la colonne ne devrait-elle pas être column-{my-custom-post-type} et non pas la valeur par défaut?

Puis-je en quelque sorte forcer la largeur de la colonne à auto ou définir sa classe pour qu'elle corresponde à mon type de post-personnalisation?

Voici ce que j'ai fait jusqu'à présent:

Type de message personnalisé

function registerPersonnelPostType() {
    $labels = array(
        'name'                  => __( 'Personnel', 'xxx' ),
        'singular_name'         => __( 'Personnel', 'xxx' ),
        'add_new'               => __( 'Add New', 'xxx' ),
        'add_new_item'          => __( 'Add New Personnel Member', 'xxx' ),
        'edit_item'             => __( 'Edit Personnel Member', 'xxx' ),
        'new_item'              => __( 'New Personnel Member', 'xxx' ),
        'view_item'             => __( 'View Personnel Member', 'xxx' ),
        'search_items'          => __( 'Search Personnel', 'xxx' ),
        'not_found'             => __( 'No personnel found', 'xxx' ),
        'not_found_in_trash'    => __( 'No personnel found in Trash', 'xxx' ),
        'parent_item_colon'     => __( 'Parent Personnel:', 'xxx' ),
        'menu_name'             => __( 'Personnel', 'xxx' )
    );

    $args = array(
        'labels'                => $labels,
        'hierarchical'          => true,
        'description'           => 'Staff names and descriptions',
        'supports'              => array( 'title', 'editor', 'thumbnail' ),
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 20,
        'show_in_nav_menus'     => true,
        'publicly_queryable'    => true,
        'exclude_from_search'   => false,
        'has_archive'           => true,
        'query_var'             => true,
        'can_export'            => true,
        'rewrite'               => true,
        'capability_type'       => 'post'
    );

    register_post_type( 'personnel', $args );
}

Taxonomie

function departmentInit() {
    $labels = array(        
        'name'                  => __( 'Department', 'xxx' ),
        'singular_name'         => __( 'Department', 'xxx' ),
        'search_items'          => __( 'Search Departments', 'xxx' ),
        'all_items'             => __( 'All Departments', 'xxx' ),
        'parent_item'           => __( 'Parent Department', 'xxx' ),
        'parent_item_colon'     => __( 'Parent Department:', 'xxx' ),
        'edit_item'             => __( 'Edit Department', 'xxx' ),
        'update_item'           => __( 'Update Department', 'xxx' ),
        'add_new_item'          => __( 'Add New Department', 'xxx' ),
        'new_item_name'         => __( 'New Department Name', 'xxx' ),
        'menu_name'             => __( 'Department', 'xxx' )
    );

    $args = array(
        'labels'                => $labels,
        'hierarchical'          => true,
        'show_ui'               => true,
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'department' )
    );

    register_taxonomy( 'department' , array('personnel'), $args );
}

Crochets pour l'édition de colonnes

add_filter( 'manage_edit-department_columns', 'departmentColumns' );

function departmentColumns( $columns ) {    
    if ( isset( $columns[ 'description' ] ) ) {
        unset( $columns[ 'description' ] );
    }

    return $columns;        
}
1
micadelli

Cela devrait faire l'affaire:

add_action( 'admin_print_styles', 'cor_admin_print_styles', 200 );
function cor_admin_print_styles() {
    $screen = get_current_screen();
    if ( 'edit-tags' === $screen->base && 'department' === $screen->taxonomy ) {
        echo <<<EOF
<style>
    .fixed .column-posts {
        width: auto;
    }
    .widefat .num, .column-comments, .column-links, .column-posts {
        text-align: left;
    }
</style>
EOF;
    }
}
1
user5424

Ajoutez le code suivant dans le fichier functions.php pour y parvenir:

add_action('admin_head', 'my_custom_fonts');

function my_custom_fonts() {
  echo '<style>
   #posts.column-posts{width:auto;}
} 
</style>';
}
0
Vinod Dalvi