我似乎无法使用 Wordpress 媒体上传检索特定的图像类型,例如缩略图、缩略图或后缩略图。
我得到的只是图像原始大小的 url,因此我显示了一个巨大的图像而不是缩略图或定义的图像大小。
这是我的脚本:
jQuery("#submit_logo_button").click(function(e){
e.preventDefault();
var custom_file_frame;
if (typeof(custom_file_frame)!=="undefined") {
custom_file_frame.close();
}
//Create WP media frame.
custom_file_frame = wp.media.frames.customHeader = wp.media({
//Title of media manager frame
title: "Thumbs - Choose Logo",
library: {
type: 'image'
},
button: {
//Button text
text: "Select Logo"
},
size: "post-thumbnail",//shouldn't this work?!?
//Do not allow multiple files, if you want multiple, set true
multiple: false
});
//callback for selected image
custom_file_frame.on('select', function() {
var attachment = custom_file_frame.state().get('selection').first().toJSON();
jQuery("#image_thumbnail").attr("src", attachment.url);
});
//Open modal
custom_file_frame.open();
});
谢谢 :)