在媒体库屏幕中显示图像大小

时间:2011-10-12 作者:Francesco Di Candia

我正在尝试在媒体库屏幕中添加图像大小,以便简单地处理图像。有人比我先做吗?感谢您的帮助。弗朗西斯科

2 个回复
SO网友:Rarst

Code based on Custom Sortable Columns

add_filter(\'manage_upload_columns\', \'size_column_register\');

function size_column_register($columns) {

    $columns[\'dimensions\'] = \'Dimensions\';

    return $columns;
}

add_action(\'manage_media_custom_column\', \'size_column_display\', 10, 2);

function size_column_display($column_name, $post_id) {

    if( \'dimensions\' != $column_name || !wp_attachment_is_image($post_id)) return;

    list($url, $width, $height) = wp_get_attachment_image_src($post_id, \'full\');

    echo esc_html("{$width}×{$height}");
}
SO网友:Marc

谢谢,我已经找了一会儿了。

和尺寸(表示重量)

add_filter( \'manage_media_columns\', \'sk_media_columns_filesize\' );
/**
 * Filter the Media list table columns to add a File Size column.
 *
 * @param array $posts_columns Existing array of columns displayed in the Media list table.
 * @return array Amended array of columns to be displayed in the Media list table.
 */
function sk_media_columns_filesize( $posts_columns ) {
    $posts_columns[\'filesize\'] = __( \'File Size\', \'my-theme-text-domain\' );

    return $posts_columns;
}

add_action( \'manage_media_custom_column\', \'sk_media_custom_column_filesize\', 10, 2 );
/**
 * Display File Size custom column in the Media list table.
 *
 * @param string $column_name Name of the custom column.
 * @param int    $post_id Current Attachment ID.
 */
function sk_media_custom_column_filesize( $column_name, $post_id ) {
    if ( \'filesize\' !== $column_name ) {
        return;
    }

    $bytes = filesize( get_attached_file( $post_id ) );

    echo size_format( $bytes, 2 );
}

add_action( \'admin_print_styles-upload.php\', \'sk_filesize_column_filesize\' );
/**
 * Adjust File Size column on Media Library page in WP admin
 */
function sk_filesize_column_filesize() {
    echo
    \'<style>
        .fixed .column-filesize {
            width: 10%;
        }
    </style>\';
}

结束

相关推荐

使用media-pload.php通过自定义字段上传mp3

我正在尝试使用带有自定义字段的Thickbox文件上传对话框来允许用户上传mp3。我想做的是抓取上传的mp3的URL并将其保存为Posteta(在我有数据时保存数据不是问题,但获取我需要的数据是!)。我有代码可以让它在图像上工作 jQuery(function($){ var formfield = null; $(\'#rps_upload_mp3\').click(function() { $(\'html\').addClass(\'Image\'