如何为我的定制主题创建配色方案?

时间:2013-02-06 作者:Dejo Dekic

我想为我的自定义模板创建颜色方案,可以在我的管理面板中更改。根据this thread 这可以“轻松”完成
作者引用:“在单独的样式表中创建您的颜色样式,并将其命名为。blue.css-black.css-brown.css-etc…然后在您的管理选项面板中,您可以添加这样简单的内容”:

array( "name" => "Color Scheme",  //color scheme
"desc" => "Select the color scheme for the theme",
"id" => $shortname."_color_scheme",
"type" => "select",
"options" => array("black","blue","brown","green","grey","orange","purple","red","white","yellow"),
"std" => "blue/blue"),
现在我不明白的是在哪里添加代码 我尝试将其添加到我的:函数中。php和索引。php,但它打破了我的主题!这是我第一次尝试创建这样的东西,所以我很抱歉我的noob问题
有人能帮我添加此功能吗
谢谢大家!!

1 个回复
最合适的回答,由SO网友:Dejo Dekic 整理而成

这是我问题的答案
将其添加到您的函数中。php

// Options Page Functions
function themeoptions_admin_menu() 
{
// here\'s where we add our theme options page link to the dashboard sidebar
add_theme_page("Theme Color", "Theme Color", \'edit_themes\', basename(__FILE__), \'themeoptions_page\');
}

function themeoptions_page() 
{
// here\'s the main function that will generate our options page 
if ( $_POST[\'update_themeoptions\'] == \'true\' ) { themeoptions_update(); }
//if ( get_option() == \'checked\'
?>
<div class="wrap">
    <div id="icon-themes" class="icon32"><br /></div>
    <h2>Theme Color</h2>
    <form method="POST" action="">
        <input type="hidden" name="update_themeoptions" value="true" />
        <h4>Colour Stylesheet To Use</h4>
        <select name ="colour">
            <?php $colour = get_option(\'mytheme_colour\'); ?>
            <option value="red" <?php if ($colour==\'red\') { echo \'selected\'; } ?> >Red Stylesheet</option>
            <option value="green" <?php if ($colour==\'green\') { echo \'selected\'; } ?>>Green Stylesheet</option>
            <option value="blue" <?php if ($colour==\'blue\') { echo \'selected\'; } ?>>Blue Stylesheet</option>
        </select>           
        <p><input type="submit" name="search" value="Update Options" class="button" /></p>
    </form>
</div>
<?php
    }
    function themeoptions_update()
   {
// this is where validation would go
update_option(\'mytheme_colour\',     $_POST[\'colour\']);  
if ($_POST[\'display_search\']==\'on\') { $display = \'checked\'; } else { $display = \'\'; }
update_option(\'mytheme_display_search\',     $display);  
    }
    add_action(\'admin_menu\', \'themeoptions_admin_menu\');
下一步是向标题添加代码。php:

<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( \'stylesheet_url\' ); ?>" />
<link rel="stylesheet" href="<?php bloginfo(\'stylesheet_directory\'); ?>/<?php echo get_option(\'mytheme_colour\'); ?>.css" type="text/css">  
最后一步是添加我们的css文件(我将其命名为red.css),并将其样式如下:

#blog{
float: left;
width: 520px;
padding: 0 10px 10px 10px;
background-color:red !important;//now if user selects "Red Stylesheet" inside admin
                                    //area it will import an override default styling
                                    (in my case default is a white color)


   }
你就完了!!希望这能帮助别人!!

结束

相关推荐

Wp_options表的查询速度较慢

我一直在跟踪基于WP的站点的慢速查询日志(默认值为a long_query_time 设置为10),我注意到以下查询经常被记录-# User@Host: root[root] @ localhost [] # Query_time: 0 Lock_time: 0 Rows_sent: 394 Rows_examined: 458 SELECT option_name, option_value FROM wp_options WHERE autoload = \'yes\';