wordrpess添加主题设置
wordpress添加主题设置选项
$themename = "32xp"; //主题名称
$shortname = "32xp"; //主题简写,必须是英文、数字、下划线组合
function mytheme_page (){
if ( count($_POST) > 0 && isset($_POST['mytheme_settings']) ){
$options = array ('keywords','description','tongji','announcement','logourl','beian');
foreach ( $options as $opt ){
delete_option ( 'mytheme_'.$opt, $_POST[$opt] );
add_option ( 'mytheme_'.$opt, $_POST[$opt] );
}
}
add_theme_page(__('32XP主题设置'), __('32xp主题设置'), 'edit_themes', basename(__FILE__), 'mytheme_settings');
}
function mytheme_settings(){?>
<style type="text/css">
ruby {
font-size:60px;
color:red;
font-family:微软雅黑;
}
.tab {
border:solid 1px;
border-color:#aaa;
width:960px;
margin:10px auto auto 10px;
text-align:left;
}
.hd {
height:25px;
width:100%;
border-bottom:solid 1px;
border-color:#aaa;
}
.hd ul {
padding:0;
margin:0;
height:26px;
overflow: hidden;
}
.hd .nomal {
font-size:14px;
height:26px;
line-height:25px;
float:left;
width:24%;
text-align:center;
border-right:solid 1px;
border-color:#aaa;
cursor:pointer;
list-style:none;
}
.hd .activeTab {
color:#2481C6;
font-weight: bold;
}
#content {
padding:20px 10px;
}
.wrap{margin: 5px 15px 0 50px;width: 600px;}
fieldset{width:100%;border:1px solid #aaa;padding-bottom:10px;margin-top:5px;-webkit-box-shadow:rgba(0,0,0,.2) 0px 0px 5px;-moz-box-shadow:rgba(0,0,0,.2) 0px 0px 5px;box-shadow:rgba(0,0,0,.2) 0px 0px 5px;}
legend{margin-left:5px;padding:0 5px;color:#2481C6;cursor:pointer;}
textarea{width:100%;font-size:11px;border:1px solid #aaa;background:none;-webkit-box-shadow:rgba(0,0,0,.2) 1px 1px 2px inset;-moz-box-shadow:rgba(0,0,0,.2) 1px 1px 2px inset;box-shadow:rgba(0,0,0,.2) 1px 1px 2px inset;-webkit-transition:all .4s ease-out;-moz-transition:all .4s ease-out;}
textarea:focus{-webkit-box-shadow:rgba(0,0,0,.2) 0px 0px 8px;-moz-box-shadow:rgba(0,0,0,.2) 0px 0px 8px;box-shadow:rgba(0,0,0,.2) 0px 0px 8px;outline:none;}
</style>
<script src="<?php bloginfo('template_url');?>/js/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
function tabClick(){
if($(this).hasClass('activeTab'))
return;
$('.hd ul li').removeClass('activeTab');
$(this).addClass('activeTab');
var tabId = $(this).attr('tabId');
$('#content > div').hide();
$('#' + tabId).show();
}
$(document).ready(function(){
$('.hd ul li').click(tabClick);
})
</script>
<form method="post" action="">
<div style="height:40px;line-height:40px;font-size:26px;font-weight: bold;">32XP主题设置</div>
<div class="tab">
<div class="hd">
<ul>
<li class="nomal activeTab" tabId="content1">SEO设置</li>
<li class="nomal" tabId="content2">首页设置</li>
<li class="nomal" tabId="content3">幻灯片设置</li>
<li class="nomal" tabId="content4">其他设置</li>
</ul>
</div>
<div id="content">
<div id="content1" style="display:block;">
<!--SEL设置-->
<fieldset>
<legend><strong>SEO设置</strong></legend>
<table class="form-table">
<tr><td>
<span>网站关键词(Meta Keywords),中间用半角逗号隔开。</span>
<textarea name="keywords" id="keywords" rows="1" cols="70"><?php echo get_option('mytheme_keywords'); ?></textarea><br />
</td></tr>
<tr><td>
<span>网站描述(Meta Description),针对搜索引擎设置的网页描述。</span>
<textarea name="description" id="description" rows="3" cols="70"><?php echo get_option('mytheme_description'); ?></textarea>
</td></tr>
<tr><td>
<span>网站统计代码</span>
<textarea name="tongji" id="tongji" rows="3" cols="70"><?php echo stripslashes(get_option('mytheme_tongji')); ?></textarea>
</td></tr>
<tr><td>
<span>网站备案号</span>
<textarea name="beian" id="beian" rows="1" cols="70"><?php echo stripslashes(get_option('mytheme_beian')); ?></textarea>
</td></tr>
</table>
</fieldset>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="保存设置" />
<input type="hidden" name="mytheme_settings" value="save" style="display:none;" />
</p>
<!--SEL设置-->
</div>
<div id="content2" style="display:none;">
首页设置
</div>
<div id="content3" style="display:none;">
幻灯片设置
</div>
<div id="content4" style="display:none;">
其他设置
</div>
</div>
</div>
</form>
<?php }
add_action('admin_menu', 'mytheme_page');
效果: