wordpress - WordPress wp.media定制

标签 wordpress media

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

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

现在,我正在努力寻找帧“ 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/

相关文章:

css - WordPress 字体系列 : "上存在 CSS 错误

django - 统一 Django 表单媒体

wordpress - wordpress 的 Multi-Tenancy 插件

html - 如何使整个图像在我的 wordpress.org 网站上可点击?

python - Django MEDIA_URL 和 MEDIA_ROOT

ios - 媒体查询像素比率不起作用

java - JMF替换

image - Orchard 1.7 MediaLibrary 内容类型上的图像以替代形状显示

wordpress - 结帐页面上的文件上传字段 woocommerce

php - MySQL查询,我该如何查询呢?