2
我有以下jQuery,它将打开wordpress媒体选择器,并将我选回的媒体文件的URL返回给我。在wordpress媒体选择器中获取多个图像
我设置了多个为true,所以我可以选择多个图像。
我的问题是如何获得第二张图片的网址。我似乎只能得到第一个。
奖金的问题 - 有没有办法将多重选择限制为只有2张图片?
jQuery(function($) {
$(document).ready(function(){
$('#insert-my-media').click(open_media_window);
});
function open_media_window() {
if (this.window === undefined) {
this.window = wp.media({
title: 'Select a Before and After image',
library: {type: 'image'},
multiple: true,
button: {text: 'Insert'}
});
var self = this; // Needed to retrieve our variable in the anonymous function below
this.window.on('select', function() {
var first = self.window.state().get('selection').first().toJSON();
wp.media.editor.insert('[banda before="' + first.url + ' after="' + second.url + '"]');
});
}
this.window.open();
return false;
}
});