最近,狮子喵看到一个游客相册预览几张图片的功能,意思就是未登录的用户可以浏览几张图片,其他图片显示为毛玻璃状态,登录后可正常浏览相册的全部图片。涉及到给相册添加自定义字段的代码如下,加到主题的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插件来实现~

发表评论

登录... 后才能评论