将使用单选按钮的自定义设置添加到WP图库

时间:2017-11-30 作者:Duc Doan

我正在为WP Gallery添加一些自定义设置。我遵循了this topic 去做吧。除了一个使用单选按钮的设置外,所有设置都已完成。这是我的代码:

<input type="radio" name="title_text_size" data-setting="gallery_image_title_text_size" value="small" />
<input type="radio" name="title_text_size" data-setting="gallery_image_title_text_size" value="medium" />
<input type="radio" name="title_text_size" data-setting="gallery_image_title_text_size" value="large" />
和我的短代码:

[gallery gallery_image_title_text_size="medium" ids="14,12,13"]
单击“编辑库”时,未选中单选按钮(中)。你有什么办法解决这个问题吗?提前感谢!

1 个回复
SO网友:El Ackabar

我也遇到了同样的问题,最终解决了。基于您拥有的线程followed, 现在必须扩展WP-core/WP-includes/js/media视图的“更新”功能。js。

转到“jQuery(document).ready(function()…”“print\\u media\\u templates”操作的一部分,然后尝试以下操作:

<script>

    jQuery(document).ready(function()
    {
      wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({

        // add your custom options template (you probably already did this)
        template: function(view){
          return wp.media.template(\'gallery-settings\')(view)
               + wp.media.template(\'custom-gallery-setting\')(view);
        },

        // now extend the update function 
        update: function( key ) {

           // call originial function: you want to *extend* it, 
           // not to override it completely!
           wp.media.view.Settings.prototype.update.call( this, key );

           // get the current value of your gallery_image_title_text_size attribute
           var currentTextSize = this.model.attributes.gallery_image_title_text_size;

           // get the data-setting elements, in your case \'gallery_image_title_text_size\':
           $setting = this.$( \'[data-setting="gallery_image_title_text_size"]\' );

                    // for each of this setting (if it\'s a radio button),
                    // check the value stored by your attributes 
                    // and set the radio button accordingly
                    $setting.each( function ( index ) {
                        if ( $( this ).is( \'input[type="radio"]\' ) && 
                             currentTextSize == $( this ).val() ) {
                            $( this ).attr( \'checked\', true );
                        } else {
                            $( this ).attr( \'checked\', false );
                        }

                     } );
            }
        } );
    } );           
</script>

结束

相关推荐

JQuery函数在WordPress中不起作用,但在jsfiddle中起作用

编辑-此问题已解决感谢您的帮助,在以下建议未能解决问题后,我刷新了浏览器现金,现在我的功能正常。。。然而,我后来意识到他们只在主页上工作。为此创建单独的线程。谢谢你的帮助!!!新线程在这里jQuery functions only work on homepage我试图做一个文本装饰:下划线;WordPress中p span“西班牙语|英语”的主动功能。我在这个jsfiddle工作https://jsfiddle.net/TonyTheOnly/k92ayp24/与JSFIDLE中的html和css相同,