定制器API和Add_Panel()。面板未显示

时间:2015-02-23 作者:Michał Kalkowski

我试图将面板添加到自定义程序中,但下面的代码不起作用(面板不显示在自定义程序容器中)。我的代码:

add_action( \'customize_register\', \'customizer_test\' );
function customizer_test($wp_customize) {
    $wp_customize->add_panel( \'panel_id\', array(
        \'priority\'       => 10,
        \'capability\'     => \'edit_theme_options\',
        \'title\'          => __(\'Theme Options\', \'mytheme\'),
        \'description\'    => __(\'Several settings pertaining my theme\', \'mytheme\'),
    ) );
    //sections
    $wp_customize->add_section( \'header_settings\', array(
        \'priority\'       => 10,
        \'capability\'     => \'edit_theme_options\',
        \'title\'          => __(\'Header Settings\', \'mytheme\'),
        \'description\'    =>  __(\'Header elements configuration\', \'mytheme\'),
        \'panel\'  => \'panel_id\',
    ) );

    $wp_customize->add_section( \'footer_settings\', array(
        \'priority\'       => 10,
        \'capability\'     => \'edit_theme_options\',
        \'title\'          => __(\'Footer Settings\', \'mytheme\'),
        \'description\'    =>  __(\'Footer elements configuration\', \'mytheme\'),
        \'panel\'  => \'panel_id\',
    ) );

}

3 个回复
SO网友:thangavel .R

你想add_settingadd_control 到您的面板才能工作。

例如:

function panel($wp_customize){

$wp_customize->add_panel(\'some_panel\',array(
    \'title\'=>\'Panel1\',
    \'description\'=> \'This is panel Description\',
    \'priority\'=> 10,
));


$wp_customize->add_section(\'section\',array(
    \'title\'=>\'section\',
    \'priority\'=>10,
    \'panel\'=>\'some_panel\',
));


$wp_customize->add_setting(\'setting_demo\',array(
    \'defaule\'=>\'a\',
));


$wp_customize->add_control(\'contrl_demo\',array(
    \'label\'=>\'Text\',
    \'type\'=>\'text\',
    \'section\'=>\'section\',
    \'settings\'=>\'setting_demo\',
));}   add_action(\'customize_register\',\'panel\');

SO网友:Calvin Koepke

首先,为面板使用不同的idpanel_id.

如果没有关联的控件和设置,您的分区将不会显示,如果没有关联的分区,面板也不会显示。

尝试向每个部分添加控件,这将解决您的问题。

SO网友:Chris Shabani Muswamba

这段代码对我有用

<? php
        
/**
  * Add panel | custom section and settings
  */
function firstest_news_theme_customize_register( $wp_customize ) {
        // add panel
        // Add Theme Options Panel.
        $wp_customize->add_panel( \'theme_option_panel\',
            array(
                \'title\'      => esc_html__( \'Theme Options\', \'wp-firstest-news-theme\' ),
                \'priority\'   => 20,
                \'capability\' => \'edit_theme_options\',
            )
        );
    
        // Global Section Start.*/
    
        $wp_customize->add_section( \'social_option_section_settings\',
            array(
                \'title\'      => esc_html__( \'Social Profile Options\', \'wp_firstest_news_theme\' ),
                \'priority\'   => 120,
                \'capability\' => \'edit_theme_options\',
                \'panel\'      => \'theme_option_panel\', //Refence to panel above
            )
        );
    
                /*Social Profile*/
                $wp_customize->add_setting( \'social_profile\',
                    array(
                        \'default\'           => $default[\'social_profile\'],
                        \'capability\'        => \'edit_theme_options\'
                        // \'sanitize_callback\' => \'wp_firstest_news_theme_sanitize_checkbox\',
                    )
                );
                $wp_customize->add_control( \'social_profile\',
                    array(
                        \'label\'    => esc_html__( \'Global Social Profile ( Nav Right )\', \'wp-firstest-news-theme\' ),
                        \'section\'  => \'social_option_section_settings\',
                        \'type\'     => \'checkbox\',
    
                    )
                );
    
        // Global section start **************************
       $wp_customize->add_section(\'theme-option\', array(
         \'title\' => __(\'Edit Carousel\', \'wp-firstest-news-theme\'),
         \'description\' => sprintf(__(\'Options for showcase\', \'wp-firstest-news-theme\')),
         \'priority\' => 130,
         \'capability\' => \'edit_theme_options\',
         \'panel\'      => \'theme_option_panel\' 
       ));
    
       // Add image slider
       $wp_customize->add_setting(\'slider_1_image\', array(
         \'default\'  => get_bloginfo(\'template_directory\') . \'/img/shocase1.jpg\', \'wp-firstest-news-theme\',
         \'type\'     => \'theme_mod\'
       ));
    
       // Add control
       $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, \'slider_1_image\', array(
         \'label\'    =>esc_html( __(\'Slider Image 1\', \'wp-firstest-news-theme\')),
         \'section\'  => \'theme-option\',
         \'setting\' => \'slider_1_image\',
         \'priority\' => 1
       )));
    
       // Add settings slider 1 heading
       $wp_customize->add_setting(\'showcase_1_heading\', array(
         \'default\'  => _x(\'Another example headline.\', \'wp-firstest-news-theme\'),
         \'type\'     => \'theme_mod\'
       ));
    
       // Add control
       $wp_customize->add_control(\'showcase_1_heading\', array(
         \'label\'    => esc_html(__(\'heading\', \'wp-firstest-news-theme\')),
         \'section\'  => \'theme-option\',
         \'priority\' => 2
       ));
    }
     add_action( \'customize_register\', \'firstest_news_theme_customize_register\' );
    
     ?>

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register