gpt4 book ai didi

wordpress - WordPress wp.media定制

转载 作者:行者123 更新时间:2023-12-03 08:06:14 25 4
gpt4 key购买 nike

我希望用户单击一个按钮以打开媒体窗口,仅显示上传到特定页面的帖子。

然后,我希望他们的选择填充输入字段。

现在,我正在努力寻找帧“ post”类型和“ select”类型之间的中间点。

如果将wp.media框架设置为“发布”,则可以看到上传到该发布的图像,但是不能插入输入字段,如果设置为“选择”,则不能将选项限制为“上传到发布” ”。

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;

});

最佳答案

这样使用

/* 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(){

关于wordpress - WordPress wp.media定制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26665333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com