wp_customize是WordPress外观自定义的功能开发,需要学习wp_customize的使用,能方便的主题使用者的使用下面就直接贴代码吧,方便以后使用!
//自定义logo
function puma_customize_register( $wp_customize ) {
$wp_customize->add_section('header_logo',array(
'title' => '博主头像',
'priority' => 50
) );
$wp_customize->add_setting( 'header_logo_image', array(
'default' => '',
"transport" => "postMessage",
'type' => 'option'
) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'header_logo_image', array(
'label' => '博主头像',
'section' => 'header_logo'
) ) );
}
add_action( 'customize_register', 'puma_customize_register' );
//自定义博主描述
function ms_customize_register( $wp_customize ) {
$wp_customize->add_section('header_bzms',array(
'title' => '博主描述',
'priority' => 50
) );
$wp_customize->add_setting( 'header_bzms', array(
'default' => '',
"transport" => "postMessage",
'type' => 'option'
) );
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'header_bzms', array(
'label' => '逼格首页的描述文字',
'section' => 'header_bzms'
) ) );
}
add_action( 'customize_register', 'ms_customize_register' );
//自定义地址
function dz_customize_register( $wp_customize ) {
$wp_customize->add_section('header_dzzb',array(
'title' => '地址坐标',
'priority' => 50
) );
$wp_customize->add_setting( 'header_dzzb', array(
'default' => '',
"transport" => "postMessage",
'type' => 'option'
) );
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'header_dzzb', array(
'label' => '逼格首页的地址坐标',
'section' => 'header_dzzb'
) ) );
}
add_action( 'customize_register', 'dz_customize_register' );
//调用就简单了,直接
<?php echo get_option('header_bzms'); ?>
下面对wp_customize做个延伸科普:
WordPress默认的Section
title_tagline – Site Title & Tagline (网站标题和描述)
colors – Colors(颜色)
header_image – Header Image (顶部图片)
background_image – Background Image (背景图片)
nav – Navigation (导航菜单)
static_front_page – Static Front Page (静态首页)
Controller Class
WP_Customize_Control() – 创建一个允许用户输入纯文本的控制器,也是下面要介绍的class的parent class
WP_Customize_Color_Control() – 创建一个允许用户从色轮中选择颜色的颜色选择器
WP_Customize_Upload_Control() – 创建允许用户上传媒体文件的控制器
WP_Customize_Image_Control() – 创建上传图片或从媒体库中选择图片的控制器
WP_Customize_Background_Image_Control() – 创建背景图片选择器
WP_Customize_Header_Image_Control() – 创建顶部背景图片选择器