现在越来越多的主题都采用原生的customizer来作为主题的后台设置选项。如果我们不懂这个框架。又想自己新增设置选项呢。下面有很好的例子。你自需要举一反三就能搞定了。

function my_customize_register( $wp_customize ) {
$wp_customize->add_control(
        'footercopyrighttxt',
        array(
            'label'      => 'Footer Copyright Text',
            'section'    => 'theme_setting',
            'settings'   => 'footercopyright',
            'type'		 => 'textarea'
        )
);
$wp_customize->add_control(
       new WP_Customize_Image_Control(
           $wp_customize,
           'logoimg',
           array(
               'label'      => __( 'Upload a logo', 'ie' ),
               'section'    => 'theme_setting',
               'settings'   => 'logoimage'
           )
       )
   );
}
}
add_action( 'customize_register' , 'my_customize_register' );

把上面的代码放在你主题的functions.php文件里。然后我们就是通过代码来调用设个设置选项。具体例子如下:

The WordPress Toolbox
Unlimited Downloads: 500,000+ WordPress Themes, Plugins, Templates & Design Assets

教程:如何新增customizer章节

DOWNLOAD NOW

<span><?php echo get_option('footercopyright'); ?></span>

<?php if(get_option('logoimage') != ""){ ?>
               <a href="<?php echo site_url(); ?>">
                <img src="<?php echo get_option('logoimage'); ?>" alt="#"/>
              </a>
              <?php } ?>

完了。本教程就这么简单。

发表回复