项目需求:
1.添加多套style文件不定期 切换风格
2.后台方便切换管理
插件实现
步骤1.
在当前的主题文件下找到functions.php文件 没有的话自己写一个
copy如下代码到文件
$themename = "My theme"; $shortname = "MT"; $options = array ( array( "name" => "Style Sheet", "desc" => "Enter the Style Sheet you would like to use for Sweet Ass Theme", "id" => $shortname."_style_sheet", "type" => "select", "options" => array("default", "green", "blue", "yellow"), "std" => "default"), ); //presentation// function mytheme_add_admin() { global $themename, $shortname, $options; if ( $_GET['page'] == basename(__FILE__) ) { if ( 'save' == $_REQUEST['action'] ) { foreach ($options as $value) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } foreach ($options as $value) { if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } } header("Location: themes.php?page=functions.php&saved=true"); die; } else if( 'reset' == $_REQUEST['action'] ) { foreach ($options as $value) { delete_option( $value['id'] ); } header("Location: themes.php?page=functions.php&reset=true"); die; } } add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin'); } function mytheme_admin() { global $themename, $shortname, $options; if ( $_REQUEST['saved'] ) echo ''; if ( $_REQUEST['reset'] ) echo ''.$themename.' settings saved.
'; ?>'.$themename.' settings reset.
Settings