我希望用户点击打开媒体窗口的按钮,只显示上传到特定页面的帖子。
然后我希望他们的选择填充输入字段。
现在我正在努力寻找框架“post”类型和“select”类型之间的中间地带。
如果我将wp.media框架设置为“post”,我可以看到上传到帖子的图片,但是我无法插入到输入字段中,如果我设置为“select”,我就不能将选项限制为“上传到帖子“。
var uploader;
$j(document).on('click','input[name="uploader_submit"]',function(){
var button = $j(this);
var parent = button.parents('.uploader');
var input = $j('input:text:first',parent);
/* Extend the wp.media object */
uploader = wp.media.frames.file_frame = wp.media({
title: "Choose Media",
button: { text: "Choose Media" },
multiple: false,
library: { type: "image" },
frame: "post"
});
/* When a file is selected, grab the URL and set it as the text field's value */
uploader.on('select',function(){
attachment = uploader.state().get('selection').first().toJSON();
input.val(attachment.url);
});
/* Open the uploader dialog */
uploader.open();
return false;
});
答案 0 :(得分:0)
像这样使用
/* Extend the wp.media object */
uploader = wp.media.frames.file_frame = wp.media({
title: "Choose Media",
button: { text: "Choose Media" },
multiple: false,
library: { type: "image" },
frame: "post",
state: "insert"
});
/* When a file is selected, grab the URL and set it as the text field's value */
uploader.on('insert',function(){