Настройте мою пользовательскую таблицу таксономии в панели администратора
Я зарегистрировал новую таксономию для своего пользовательского типа записи, и теперь я пытаюсь отредактировать таблицу таксономии.
Я успешно удалил столбец описания, но не могу понять , как изменить ширину столбца для столбца, который показывает количество пользовательских типов записей, найденных в этой конкретной таксономии. CSS-класс столбца, по-видимому, column-posts
, и, таким образом, его ширина установлена на 10%
.
Не должен ли класс CSS столбца быть column-{my-custom-post-type}
, а не по умолчанию?
Могу ли я каким-то образом установить ширину столбца в auto
или установить его класс в соответствии с моим пользовательским типом записи?
Вот что я сделал до сих пор:
Пользовательский Тип Записи
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 );
}
Таксономия
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 );
}
Крючки для редактирования столбцов
add_filter( 'manage_edit-department_columns', 'departmentColumns' );
function departmentColumns( $columns ) {
if ( isset( $columns[ 'description' ] ) ) {
unset( $columns[ 'description' ] );
}
return $columns;
}
2 answers
Это должно сработать:
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;
}
}
Добавьте следующий код в functions.php файл для достижения этой цели:
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo '<style>
#posts.column-posts{width:auto;}
}
</style>';
}