如何在 WordPress 仪表板的管理栏中排列列?

How to arrange columns in my Admin bar in WordPress dashboard?

我在 functions.php 中使用以下代码在 WordPress 仪表板上显示每个帖子特色图片的 60x60 图片缩略图,但它显示在第 3 列中,我希望它首先显示在标题栏的左侧 - 似乎无法完成这项工作 - 有人有什么建议吗?

// show featured images in dashboard
add_image_size( 'showimg-admin-post-featured-image', 60, 60, false );

// Add the posts and pages columns filter. both use the same function.
add_filter('manage_posts_columns', 'showimg_add_post_admin_thumbnail_column', 2);
add_filter('manage_pages_columns', 'showimg_add_post_admin_thumbnail_column', 2);

// Add the featured image column
function showimg_add_post_admin_thumbnail_column($showimg_columns){
    $showimg_columns['showimg_thumb'] = __('Featured Image');
    return $showimg_columns;
}

// Manage Post and Page Admin Panel Columns
add_action('manage_posts_custom_column', 'showimg_show_post_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'showimg_show_post_thumbnail_column', 5, 2);

// Get featured-thumbnail size post thumbnail and display it
function showimg_show_post_thumbnail_column($showimg_columns, $showimg_id){
    switch($showimg_columns){
        case 'showimg_thumb':
        if( function_exists('the_post_thumbnail') ) {
            echo the_post_thumbnail( 'showimg-admin-post-featured-image' );
        }
        else
            echo 'hmm… your theme doesn\'t support featured image…';
        break;
    }
}  

将项目插入数组中复选框(索引 0)的右侧。

使用array_mergearray_slice添加到列数组。

// Add the featured image column
function showimg_add_post_admin_thumbnail_column($showimg_columns){
    $new_column['showimg_thumb'] = __('Featured Image');
    return array_merge(
        array_slice( $showimg_columns, 0, 1, true ),
        $new_column,
        array_slice( $showimg_columns, 1, null, true )
    );
}

供参考...默认的列顺序数组是这样的:

array(
    'cb'         => '<input type="checkbox" />',
    'title'      => "Title",
    'author'     => "Author",
    'categories' => "Categories",
    'tags'       => "Tags",
    'comments'   => '<span class="vers comment-grey-bubble" title="Comments"><span class="screen-reader-text">Comments</span></span>',
    'date'       => "Date"
);