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;
}
});