将主题选项页面转换为也可在Customize.php中使用?

时间:2014-08-24 作者:alex

我开发了一个主题选项页面,它是外观的子菜单页面。但现在我想知道我需要怎么做,这样主题选项也可以在主题->自定义界面中编辑。(customize.php)。

我尝试了一个简单的测试,将其添加到函数中。php,查看自定义菜单是否已更改,但运气不佳

//for customize.php
function mytheme_customize_register( $wp_customize ) {
   //All our sections, settings, and controls will be added here
   //1. Define a new section (if desired) to the Theme Customizer
      $wp_customize->add_section( \'mytheme_options\', 
         array(
            \'title\' => __( \'MyTheme Options\', \'ppr\' ), //Visible title of section
            \'priority\' => 35, //Determines what order this appears in
            \'capability\' => \'edit_theme_options\', //Capability needed to tweak
            \'description\' => __(\'Allows you to customize some example settings for MyTheme.\', \'ppr\'), //Descriptive tooltip
         ) 
      );

      //2. Register new settings to the WP database...
      $wp_customize->add_setting( \'link_textcolor\', //No need to use a SERIALIZED name, as `theme_mod` settings already live under one db record
         array(
            \'default\' => \'#2BA6CB\', //Default setting/value to save
            \'type\' => \'theme_mod\', //Is this an \'option\' or a \'theme_mod\'?
            \'capability\' => \'edit_theme_options\', //Optional. Special permissions for accessing this setting.
            \'transport\' => \'postMessage\', //What triggers a refresh of the setting? \'refresh\' or \'postMessage\' (instant)?
         ) 
      );      

    //
}
add_action( \'customize_register\', \'mytheme_customize_register\' );
//end cutomize.php
谨致问候,

1 个回复
最合适的回答,由SO网友:Bryan Willis 整理而成

您需要向其添加控件。

function mytheme_customize_register( $wp_customize ) {

  $wp_customize->add_section( \'mytheme_options\', 
     array(
        \'title\' => __( \'MyTheme Options\', \'ppr\' ),
        \'priority\' => 35,
        \'description\' => __(\'Allows you to customize some example settings for MyTheme.\', \'ppr\'),
     ) 
  );

$wp_customize->add_setting( \'link_textcolor\', array(
    \'default\' => get_option( \'your_theme_page_option_value\' ), THIS IS THE OPTION NAME YOU CREATED WITH YOUR OPTIONS PAGE CODE
    \'type\' => \'option\',  // FOR OPTIONS USE OPTION
    \'capability\' => \'edit_theme_options\',
    \'transport\' => \'refresh\', // WILL REFRESH INSTEAD OF JS. YOU HAVE TO WRITE JS TO MAKE UPDATE INSTANT... ITS A PAIN IN THE ASS http://codex.wordpress.org/Plugin_API/Action_Reference/customize_preview_init
) );


// THIS IS WHAT YOU WERE MISSING
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, \'link_color\', array(
    \'label\'        => __( \'Link Text Color\', \'ppr\' ),
    \'section\'    => \'mytheme_options\', // ID OF SECTION ABOVE
    \'settings\'   => \'link_textcolor\', // ID OF SETTINGS ABOVE
) ) );

}
 add_action( \'customize_register\', \'mytheme_customize_register\' );
Alex请确保您在模板中包含选项,否则您将看不到任何更改。例如,如果您想使用所有模板中的选项,请确保您实际将该选项放在标题或所有需要更改的文件中。

因此,对于上面的代码,我将使用类似的内容,并将其放在标题中。php,甚至只是在使用wp_head 如果是针对样式,请执行操作。

function mytheme_customizer_styles() {
        $link_text_color = get_option(\'your_theme_page_option_value\'); // THIS IS THE OPTION VALUE THAT YOU CREATED WITH SETTINGS API AND YOUR CUSTOM OPTIONS PAGE AND IS ALSO THE NAME OF THE OPTIONS DEFINED IN THE `add_setting` field above.
    ?>
    <style type="text/css" id="mytheme-customizer-admin-header-css">
         .link-text-color { color:  <?php echo $link_text_color; ?>; }
    </style>
    <?php
}
add_action( \'wp_head\', \'mytheme_customizer_styles\', 9999); // JUST MAKE SURE THE PRIORITY IS LATE ENOUGH SO ITS NOT OVERRIDEEN

结束

相关推荐

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