简体   繁体   English

更改Wordpress发布类别颜色

[英]Change wordpress post category colors

I have a navigation bar on my wordpress blog which displays post categories. 我的wordpress博客上有一个导航栏,用于显示帖子类别。 I would like each category to have a different background color on the nav bar and when displayed on other pages. 我希望每个类别在导航栏上以及在其他页面上显示时具有不同的背景色。 I found the following php code for the functions.php file, and it works to add a selection box for colors in the post categories admin page. 我为functions.php文件找到了以下PHP代码,它可以在帖子类别管理页面中为颜色添加选择框。 The color selection box works, however this code does not change colors on the site on its own. 颜色选择框有效,但是此代码不会自行更改网站上的颜色。 I'm new to wordpress and need to know what other files need to be edited and in what way to make this work. 我是Wordpress的新手,需要知道还需要编辑哪些其他文件以及以何种方式进行这项工作。 Any help would be appreciated. 任何帮助,将不胜感激。

<?php
add_action('edit_category_form', 'add_extra_fields');
add_action('edited_category', 'save_extra_fields');
function add_extra_fields($tag)
{
    $colors = array('Black' => '000', 'White' => 'FFF');
    $selected = get_option('category_'.$tag->term_id.'_color');
    echo '<select name="cat_color">';
    foreach($colors as $name => $hex)
    {
        echo '<option value="'.$hex.'"'.($hex == $selected ? ' selected="selected"' : '').'>'.$name.'</option>';
    }
    echo '</select>';
}
function save_extra_fields($term_id)
{
    if($_POST['cat_color'])
    {
        update_option('category_'.$term_id.'_color', $_POST['cat_color']);
    }
}
?>

不会的,您需要修改导航条形码以使用表单中的新元数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM