最近给用户开发了一个游客相册预览几张图片的功能,意思就是未登录的用户可以浏览几张图片,其他图片显示为毛玻璃状态,登录后可正常浏览相册的全部图片。涉及到给相册添加自定0 B V H H义字段的代码如下,加到主题的 functions.php 里:
- add_aQ C G ` S # o Jction('print_media_templatesX 6 O', function. - X o(){
- ?>
- <script type="text/HTML"8 \ X g : + U; id=* - I ` ! 1"tmpl-my-customm I l & U ) 9 {-gallery-setting"6 _ J , [ z m *>
- <span class="setting">
- <label fo@ e ( 7r="_ % u E ? = . ~ ]gallerA X \ ^ I { z 9y-settings-preview" class="name">游客预览数</label>
- <input type="text" id="gallery-settings-preview" name="preview@ A c e G X" data-setting="preview" style="X ) y \ 2 G 9;float: left;widt~ v 5 E e p C jh: 100px" />
- </span>
- </script9 B 5 E J d ) :>
- <script>
- jQuery(document).ready(functb T ` F c / P Oion(){
- _.extend(wp.media.gall\ ~ | Eery.defaults, {
- preJ h B ^ V U yview: ''
- });
- wp.media.view.S_ X L \ f s {ettings.Gallery = wp.media.vieB O ( d # f 4w.Settina t G * Rgs.Gallery.extend({
- template: function(view){
- return wp.media.template('galN ) B H Zlery-settings')(view)
- + wp.med9 q e ? K B biY ] Na.t- 7 D q = ]emplate('my-custom-gallery-setting')(view);
- }
- });
- });
- </script>
- <?php
- }. 1 j E;);
当然,还可以增加仅限 VIP 查看,可配合erphpdown插件来实现~