WordPress的customizer.php没有显示部分/设置

时间:2018-09-27 19:41:57

标签: php wordpress

当我访问customr.php页面时,我遇到了Wordpress Customizer无法加载我的部分/设置的问题。

下面,我包含了我所有的customrizer.php和我的functions.php的include部分。

    <?php
    function customizer_settings( $wp_customize ) {
        $wp_customize->add_section('menu_colors', array(
            'title' => 'Menu Colors',
            'priority' => 10,
      ) );
      $wp_customize->add_setting('toggle_color', array(
        'default' => '#fff',
        'transport' => 'refresh',
      ) );
      $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'toggle_color', array(
        'label' => 'Toggle Color',
        'section' => 'menu_colors',
        'settings' => 'toggle_color',
      ) ) );
      $wp_customize->add_setting('link_color', array(
        'default' => '#fff',
        'transport' => 'refresh',
      ) );
      $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link_color', array(
        'label' => 'Menu Link Color',
        'section' => 'menu_colors',
        'settings' => 'link_color',
      ) ) );
      $wp_customize->add_setting('link_hover_color', array(
        'default' => '#fff',
        'transport' => 'refresh',
      ) );
      $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'link_hover_color', array(
        'label' => 'Menu Link Hover Color',
        'section' => 'menu_colors',
        'settings' => 'link_hover_color',
      ) ) );
      $wp_customize->add_setting('overlay_background_color', array(
        'default' => '#fff',
        'transport' => 'refresh',
      ) );
      $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'overlay_background_color', array(
        'label' => 'Overlay Background Color',
        'section' => 'menu_colors',
        'settings' => 'overlay_background_color',
      ) ) );
      $wp_customize->add_setting('menu_background_color', array(
        'default' => '#fff',
        'transport' => 'refresh',
      ) );
      $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'menu_background_color', array(
        'label' => 'Menu Background Color',
        'section' => 'menu_colors',
        'settings' => 'menu_background_color',
      ) ) );
    }
    // Setup the Theme Customizer settings and controls...
    add_action( 'customize_register' , 'customizer_settings' );

    function header_output() {
    ?>
    <!--Customizer CSS-->
    <style type="text/css">
       <?php self::generate_css('.nav-menu' , 'background-color' , 'menu_background_color', ''); ?>
       <?php self::generate_css('.collapse-btn' , 'color' , 'toggle_color', ''); ?>
       <?php self::generate_css('.collapse-btn:hover' , 'color' , 'toggle_hover_color', ''); ?>
       <?php self::generate_css('.closebtn' , 'color' , 'toggle_color', ''); ?>
       <?php self::generate_css('.closebtn:hover' , 'color' , 'toggle_hover_color', ''); ?>
       <?php self::generate_css('.overlay' , 'background-color' , 'overlay_background_color', ''); ?>
       <?php self::generate_css('.overlay li a' , 'color' , 'link_color', ''); ?>
       <?php self::generate_css('.overlay li a:hover' , 'color' , 'link_color', ''); ?>
       <?php self::generate_css('.overlay li a:focus' , 'color' , 'link_color', ''); ?>
    </style>
    <!--/Customizer CSS-->
    <?php
  }
  // Output custom CSS to live site
  add_action( 'customize_controls_print_styles', 'header_output' );
?>

这部分是functions.php theme_setup函数:

    function Sentrytheme_setup() {
      load_theme_textdomain( 'Sentrytheme' );

      //Add default posts and comments RSS feed links to head
      add_theme_support( 'automatic-feed-links' );

      //Let WordPress manage the document title
      add_theme_support( 'title-tag' );

      //Enables post thumbnails on posts and pages.
      add_theme_support( 'post-thumbnails' );

      add_theme_support('html5', array('comment-form','comment-list','gallery','caption',));

      add_theme_support('post-formats', array('aside','image','video','quote','link','gallery','audio',));

      add_theme_support('custom-logo', array('width' => 250,'height' => 100,'flex-width' => true,));

      include('/inc/customizer.php');

      add_theme_support('menus');

      function register_my_menus() {
          $args = array(
              'menu-1' => __( 'Main Menu' )
          );
          register_nav_menus( $args );
      }
      add_action( 'init', 'register_my_menus' );
    }
    add_action( 'after_setup_theme', 'Sentrytheme_setup' );

在Wordpress Admin中查看自定义程序时看到的是customizer page

这组代码(经过修改)来自https://premium.wpmudev.org/blog/wordpress-theme-customizer-guide/https://codex.wordpress.org/Theme_Customization_API

感谢您的帮助。

0 个答案:

没有答案