【问题标题】:Wordpress theme customizer - can't add section/settingsWordpress 主题定制器 - 无法添加部分/设置
【发布时间】:2015-06-09 09:34:21
【问题描述】:

我正在尝试通过添加部分和设置来修改 Worpdress 主题定制器,但无论我在 functions.php 文件中添加什么,定制器中都不会出现任何内容。

例子:

function starter_customize_register( $wp_customize ) 
{
    $wp_customize->add_section( 'mytheme_new_section_name' , array(
    'title'      => __( 'Visible Section Name', 'starter' ),
    'priority'   => 30, ) );    
}
add_action( 'customize_register', 'starter_customize_register');

我本来希望这会添加一个具有所选名称的部分,但我看到的唯一内容是来自 Wordpress 的两个初始部分(网站标题和标语,静态首页)。

我在这里找到了一个很好的教程 (http://code.tutsplus.com/series/a-guide-to-the-wordpress-theme-customizer--wp-33722)。我遵循了每一步,甚至采用了他们的示例主题,但同样没有显示新的部分或设置。

让我怀疑我的配置是否有问题。

我正在使用 wordpress 网络/多站点,不知道这是否相关。

有什么想法吗?

谢谢 洛朗

【问题讨论】:

  • 补充一句:像二十五、二十一、...这样的主题运行良好,自定义适合这些主题。

标签: php wordpress


【解决方案1】:

您需要添加设置和控件以使其工作:

function starter_customize_register( $wp_customize ) 
{
    $wp_customize->add_section( 'starter_new_section_name' , array(
        'title'    => __( 'Visible Section Name', 'starter' ),
        'priority' => 30
    ) );   

    $wp_customize->add_setting( 'starter_new_setting_name' , array(
        'default'   => '#000000',
        'transport' => 'refresh',
    ) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
        'label'    => __( 'Header Color', 'starter' ),
        'section'  => 'starter_new_section_name',
        'settings' => 'starter_new_setting_name',
    ) ) );
}
add_action( 'customize_register', 'starter_customize_register');

参考:Theme Customization API

【讨论】:

  • 非常感谢,我没有意识到在定制器中显示某些内容之前,设置和控件也必须存在。
  • 注意add_setting必须在add_control之前调用。我首先以相反的方式列出了这两个函数(add_control 上面的add_setting),但没有奏效。
  • 希望官方文档有这样的例子。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多