繁体   English   中英

Wordpress Customizer内容特定控件

[英]Wordpress Customizer content specific controls

我正在为Wordpress的自定义主题进行一项挑战。 我希望主题定制器中包含特定于内容的控件。 我知道有“ active_callback”选项,但这不足以达到我的目的,我阅读了2篇有关定制程序的文档文章,以及https://make.wordpress.org/core/2014/07/08/customizer-improvements-in -4-0 /文章,但仍然不知道,这是我想要实现的目标:

例如,我希望有“显示侧边栏”复选框,但此复选框应更符合上下文规范。 例如,当我将在主页上时,将只有一个复选框作为“显示侧边栏默认值”,但是当我进入某个帖子时,我希望有3个复选框:

  1. “显示默认的侧边栏”-id =“ show_sidebar”
  2. “在帖子存档页面中显示侧边栏”-id =“ show_sidebar_archive_ {post_type}”
  3. “显示此信息的侧边栏”-id =“ show_sidebar_singular_ {post_id}”

因此,当我想使用此类特定的ID进行控制时,仅active_callback不够用,因为它只能显示/隐藏控件,而当iframe中的URL更改时,我无法创建新的ID。

可能有2种解决方案:1.更好-当我可以通过上下文创建/删除控件时,这将是最好的解决方案。 如果可以使用定制工具API,请给我som提示2.不好,但是足够-至少可以通过新的单击URL重新加载整个/wp-admin/customize.php?url=吗? 这可能够一阵子了

谢谢任何建议!

好的,我想出了第二个解决方案,这是代码。 现在对我来说足够了。

'use strict';

(function ($) {

  /**
   * This is important fix for Theme Customizer
   * It will change whole customizer url, because we need to load
   * all controls ahan for new url, because of hierarchical options
   */
  if ( /\/customize\.php$/.test( window.location.pathname ) ) {
    wp.customize.bind( 'preview-ready', function() {
      var body = $( 'body' );
      body.off( 'click.preview' );
      body.on( 'click.preview', 'a[href]', function( event ) {
        var link, isInternalJumpLink;
        link = $( this );
        isInternalJumpLink = ( '#' === link.attr( 'href' ).substr( 0, 1 ) );
        event.preventDefault();

        if ( isInternalJumpLink && '#' !== link.attr( 'href' ) ) {
          $( link.attr( 'href' ) ).each( function() {
            this.scrollIntoView();
          } );
        }

        /*
         * Note the shift key is checked so shift+click on widgets or
         * nav menu items can just result on focusing on the corresponding
         * control instead of also navigating to the URL linked to.
         */
        if ( event.shiftKey || isInternalJumpLink ) {
          return;
        }
        //self.send( 'scroll', 0 );
        //self.send( 'url', link.prop( 'href' ) );

        var newUrl = link.prop( 'href' );
        var currentUrl = window.location.href;

        var customizeUrl = currentUrl.substring(0, currentUrl.indexOf("?url=") + 5) + newUrl;

        // Reload whole customizer for new url
        window.parent.location.replace(customizeUrl);
      });
    } );
  }
})(jQuery);
//# sourceMappingURL=customizer.js.map

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM