我正在做一个自定义的php页面在wp,并要求上传多个图像,并显示上传后,并选择图像显示。基本上,我想要有同样的效果,在图片库的古腾堡Wordpress。是否有任何函数使整个图片库块显示在我的php页面上?
谢谢。
发布于 2021-06-24 13:28:50
wp.media是JavaScript API WordPress用来显示媒体库模式的。
您可以通过在您的管理页面上排队定制JS脚本来使用它:
wp_enqueue_script('media-upload');
wp_enqueue_media();
wp_enqueue_script(
'pb-admin-script',
'admin.js',
array(
'jquery',
)
);然后像这样处理它:
HTML:
联署材料:
jQuery(document).ready(function($) {
$(document).on('click', '.upload_image_button', function(event) {
event.preventDefault();
var imgPrev = $('#image-preview');
var file_frame = wp.media.frames.file_frame = wp.media({
title: 'Select or upload image',
library: {
type: 'image'
},
button: {
text: 'Select'
},
multiple: false,
});
file_frame.on('select', function() {
var attachment = file_frame.state().get('selection').first().toJSON();
imgPrev.src = attachment.url;
imgPrev.style.removeProperty('display');
});
file_frame.open();
});
});https://wordpress.stackexchange.com/questions/390938
复制相似问题