【问题标题】:WordPress Dashboard: column sizing after adding custom taxonomiesWordPress仪表板:添加自定义分类后的列大小
【发布时间】:2022-07-12 22:05:21
【问题描述】:

如下面的屏幕截图所示,我在管理仪表板中的列没有换行,而且太小,无法容纳我为帖子创建的所有分类。你们有谁知道简单的修复、函数或 CSS 吗?

我不确定它是否相关,但这是我添加到 functions.php 的自定义分类代码:

add_action( 'init', 'create_subjects_hierarchical_taxonomy', 0 );
//create a custom taxonomy name it subjects for your posts

function create_subjects_hierarchical_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
// First do the translations part for GUI

// Add volume taxonomy
  $labels = array(
    'name' => _x( 'Volumes', 'taxonomy general name' ),
    'singular_name' => _x( 'Volume', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Volumes' ),
    'all_items' => __( 'All Volumes' ),
    'parent_item' => __( 'Parent Volume' ),
    'parent_item_colon' => __( 'Parent Volume:' ),
    'edit_item' => __( 'Edit Volume' ), 
    'update_item' => __( 'Update Volume' ),
    'add_new_item' => __( 'Add New Volume' ),
    'new_item_name' => __( 'New Volume Name' ),
    'menu_name' => __( 'Volumes' ),
  );    
 
// Register the taxonomy
  register_taxonomy('volumes',array('post'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'show_in_rest' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'volume' ),
  ));

【问题讨论】:

    标签: php css wordpress


    【解决方案1】:

    如果你知道怎么做,最好的解决方案是使用 enqueue 样式向管理员添加样式,但是使用操作可以快速解决,只需将其添加到你的 functions.php 文件:

    add_action( 'admin_print_styles', 'core_admin_print_styles', 200 );
    function core_admin_print_styles() {
        $screen = get_current_screen();
        if ( 'edit' === $screen->base ) {
            echo <<<EOF
            <style>
                .widefat thead td, .widefat thead th {
                    width: auto !important;
                }
            </style>
            EOF;
        }
    }
    

    这会添加一个内联样式标记并将列的宽度设置为自动。 您也可以通过引用列的类或 ID 来编辑特定列的宽度,例如“volume”可能会有一个 ID“taxonomy-volume”,因此您可以使用:

    add_action( 'admin_print_styles', 'core_admin_print_styles', 200 );
        function core_admin_print_styles() {
            $screen = get_current_screen();
            if ( 'edit' === $screen->base ) {
                echo <<<EOF
                <style>
                    #taxonomy-volume {
                        width: 15% !important;
                    }
                </style>
                EOF;
            }
        }
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 2011-07-29
      • 1970-01-01
      • 2018-12-14
      • 2013-11-22
      • 1970-01-01
      • 2012-08-01
      相关资源
      最近更新 更多