В примера по-долу извиквам Media Library на WordPress, чрез натискане на картинка.
<script>
function getmedia(ident){
// Instantiates the variable that holds the media library frame.
var meta_image_frame;
// Runs when the image button is clicked.
j(function(){
// Prevents the default action from occuring.
// e.preventDefault();
// If the frame already exists, re-open it.
if ( meta_image_frame ) {
meta_image_frame.open();
return;
}
// Sets up the media library frame
meta_image_frame = wp.media.frames.meta_image_frame = wp.media({
// title: meta_image.title,
// button: { text: meta_image.button },
library: { type: 'image' }
});
// Runs when an image is selected.
meta_image_frame.on('select', function(){
// return false;
// Grabs the attachment selection and creates a JSON representation of the model.
var media_attachment = meta_image_frame.state().get('selection').first().toJSON();
// Sends the attachment URL to our custom image input field.
document.getElementById("imgc_"+ident).src = media_attachment.sizes.thumbnail.url;
//media_attachment.id; имате и id-то на самият attachment (за повече опции, проверете в WordPress документацията)
});
// Opens the media library frame.
meta_image_frame.open();
});
}
</script>
Ето това са картинките, чрез които ще извикваме Media Library и ще заменяме src адреса.
<img src="smiley.gif" id="imgc_1" alt="Smiley face" height="42" width="42" onclick="getmedia('1');"></br>
<img src="smiley.gif" id="imgc_2" alt="Smiley face" height="42" width="42" onclick="getmedia('2');"></br>
<img src="smiley.gif" id="imgc_3" alt="Smiley face" height="42" width="42" onclick="getmedia('3');">

Полезен пост !!
Респект за якия блог!