admin管理员组文章数量:1289877
I am making a custom php page in wp-admin and required to upload multiple images and display it after upload and select images to display. Basically I would like to have the same effect as in Image Gallery of Gutenberg Wordpress. Is there any function to get the whole gallery block displayed on my php page?
Thank you.
I am making a custom php page in wp-admin and required to upload multiple images and display it after upload and select images to display. Basically I would like to have the same effect as in Image Gallery of Gutenberg Wordpress. Is there any function to get the whole gallery block displayed on my php page?
Thank you.
Share Improve this question asked Jun 24, 2021 at 3:45 murnimurni 376 bronze badges 1- ACF is exactly that. This plugin gives you the option to add custom fields (meta data) to option panel, posts, taxonomies, even menus. This will save you a lot of time of coding everything yourself – Buttered_Toast Commented Jun 24, 2021 at 7:06
1 Answer
Reset to default 2wp.media
is the JavaScript API WordPress uses to display the media library modal.
You can use it yourself by enqueueing a custom JS script on your admin page:
wp_enqueue_script('media-upload');
wp_enqueue_media();
wp_enqueue_script(
'pb-admin-script',
'admin.js',
array(
'jquery',
)
);
Then work with it like this:
HTML:
<button class="upload_image_button button button-primary">
<?php _e('Upload Image', 'pb'); ?>
</button>
<img src="" id="image-preview" style="display: none"/>
JS:
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();
});
});
本文标签: imagesHow to get the Gallery formsection just like in Gutenberg block
版权声明:本文标题:images - How to get the Gallery formsection just like in Gutenberg block? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741486756a2381439.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论