建站教程

建站教程

Products

当前位置:首页 > 建站教程 >

在WordPress后台创建相册库时添加自定义字段

GG网络技术分享 2025-03-18 16:04 0


最近的,模板兔摩班图(Mobantu.com)为用户开发了一个旅游相册中的多张图片预览功能,即未登录的用户可以浏览多张图片,其他图片显示为磨砂玻璃。 登录后,可以正常浏览相册中的所有图片。

相册添加自定义字段所涉及的代码如下,添加到主题的functions.php中:

add_action('print_media_templates', function(){

?>

<script type="text/html" id="tmpl-my-custom-gallery-setting">

<span class="setting">

<label for="gallery-settings-preview" class="name">游客预览数</label>

<input type="text" id="gallery-settings-preview" name="preview" data-setting="preview" style="float: left;width: 100px" />

</span>

</script>

<script>

jQuery(document).ready(function(){

_.extend(wp.media.gallery.defaults, {

preview: ''

});

wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({

template: function(view){

return wp.media.template('gallery-settings')(view)

+ wp.media.template('my-custom-gallery-setting')(view);

}

});

});

</script>

<?php

});

当然也可以添加只VIP查看,可以用我们的erphpdown插件来实现~

标签: WordPress 教程

提交需求或反馈

Demand feedback