Theme wp_customize 的使用
示例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2…
示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<?php
function mytheme_footer_options($wp_customize){
$wp_customize->add_section(‘mytheme_footer_options’, array(
‘title’ => __(‘网站底部数据和风格’, ‘mytheme’),
‘description’ => ‘通过这个选项设置网站底部的样式和内容’,
‘priority’ => 80,
));
$wp_customize->add_setting(‘mytheme_footer_sever_nav’, array(
‘capability’ => ‘edit_theme_options’,
‘type’ => ‘option’,
));
$wp_customize->add_control( new Ari_Customize_select_nav_Control($wp_customize, ‘mytheme_footer_sever_nav’, array(
‘label’ => __(‘底部的服务菜单’, ‘mytheme_footer_sever_nav’),
‘section’ => ‘mytheme_footer_options’,
‘settings’ => ‘mytheme_footer_sever_nav’,
‘description’ => ‘底部带有图标的服务菜单选项,选择一个菜单,若不选择的话,那么就不会显示了。’,
)
));
}
add_action( ‘customize_register’, ‘mytheme_footer_options’ );
?>
|
请注意,定制程序可以使用选项类型处理存储为键控数组的选项以进行设置。 这允许将多个设置存储在不是主题模式的单个选项中。 要检索并使用您的Customizer选项的值,请使用get_theme_mod()和get_option()与设置标识:
调用
1
|
<?php echo get_option(‘header_bzms’); ?>
|
1
|
<?php if(get_option(“header_bzms”)){ echo get_option(‘header_bzms’); } ?>
|
相关知识
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() – 创建顶部背景图片选择器
主题设置变量获取
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<?php
/**
* 主题设置变量获取
这个文件将主题所有读取数据库的值获取到变量中,在 需要调用的文件包含这个文件就直接可以输出变量而不需要在每个文件去查询数据库了。
* @see http://www.themepark.com.cn
* @author themepark
* @package theme/options
* @version 1.o
*/
$cat_get=$product_get=$all_get=”;
if(isset($_GET[‘post_type’])){
if($_GET[‘post_type’]==“post”){$cat_get=‘checked=”checked”‘;}else{$all_get=‘checked=”checked”‘;}
$key = wp_specialchars($s, 1);
}
//网站顶部设置
$mytheme_top_languge_title=get_option(‘mytheme_top_languge_title’);//顶部广告语
$mytheme_top_languge_nav=get_option(‘mytheme_top_languge_nav’);//顶部菜单
$mytheme_logo=get_option(‘mytheme_logo’);//主logo
$mytheme_logo2=get_option(‘mytheme_logo2’);//第二logo上传
$mytheme_logo_sj_1=get_option(‘mytheme_logo_sj_1’);//手机端logo1
$mytheme_logo_sj_2=get_option(‘mytheme_logo_sj_2’);//手机端logo2
//底部设置数据
$mytheme_logo3=get_option(‘mytheme_logo3’);//底部logo
$mytheme_footer_ad=get_option(‘mytheme_footer_ad’);//底部广告语
$mytheme_footer_sever_nav=get_option(‘mytheme_footer_sever_nav’);//底部服务菜单
$mytheme_footer_tel=get_option(‘mytheme_footer_tel’);//底部电话,
$mytheme_footer_contact_mail=get_option(‘mytheme_footer_contact_mail’);//底部邮箱
$mytheme_footer_fax=get_option(‘mytheme_footer_fax’);//底部传真
$mytheme_footer_contact=get_option(‘mytheme_footer_contact’);//联系地址
$mytheme_footer_bqba_ts=get_option(‘mytheme_footer_bqba_ts’);//版权所有
$mytheme_footer_bqba_ts2=get_option(‘mytheme_footer_bqba_ts2’);//ICP备案号码
$mytheme_footer_bqba_ts3=get_option(‘mytheme_footer_bqba_ts3’);//公安备案
$mytheme_footer_bqba_ts4=get_option(‘mytheme_footer_bqba_ts4’);//公安备案url
$mytheme_footer_bqba_ts5=get_option(‘mytheme_footer_bqba_ts5’);//技术支持
$mytheme_footer_sever_nav4=get_option(‘mytheme_footer_sever_nav4’);//友情链接菜单
?>
|
调用
1
2
3
4
5
6
7
8
9
10
11
12
|
//单个调用
<?php echo $mytheme_footer_btn; ?>
//多个同时调用+判断
<?php if($mytheme_footer_tel||$mytheme_footer_contact_s||$mytheme_footer_fax||$mytheme_footer_contact||$mytheme_footer_btn){?>
<div class=“footer_contact”>
<p class=“tell”><?php echo $mytheme_footer_tel; ?></p>
<p><?php echo $mytheme_footer_contact_s; ?></p>
<p><?php echo $mytheme_footer_fax; ?></p>
<p><?php echo $mytheme_footer_contact; ?></p>
<a href=“<?php echo $mytheme_footer_btn_url; ?>“><?php echo $mytheme_footer_btn; ?></a>
</div>
<?php } ?>
|
扩展内容
http://www.wazhuti.com/1825.html
http://www.wazhuti.com/1825.html
类别:WordPress开发、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!