[英]Create a meta box which display image from the gallery in wordpress
我有一個具有多個自定義文本字段(元框)的自定義帖子類型,並且我需要創建一個自定義字段,例如特色圖片的框。 這意味着將使用一個字段從媒體庫中選擇一個圖像並將其保存以供顯示。 我沒有任何自定義字段的wordpress插件。 可能嗎 ?
var frame;
$('.image-upload').on( 'click', function(e) {
e.preventDefault();
if (frame) {
frame = null;
}
frame = wp.media({
title: 'Frame title',
button: {
text: 'Frame button text'
},
multiple: false
});
frame.on( 'select', function() {
var attachment = frame.state().get('selection').first().toJSON();
var url = attachment.url;
var id = attachment.id;
});
frame.open();
});
把它放在管理js文件中。 很不言自明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.