WordPress 分类文章数量 获取
在制作 Crazy uncle 的wordpress主题的时候,不想加入复杂的设置选项。。。因为这个wordp…
在制作 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() – 创建顶部背景图片选择器
类别:WordPress教程、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!