在制造 Crazy uncle 的wordpress主题的时刻,不想到场庞杂的设置选项。。。由于这个wordpress主题实在是太甚简朴了。。。因而就从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() – 建立顶部背景图片挑选器

评论列表