您将获得一个类别的颜色(不过术语更合适)
$the_category_id = $category[0]->cat_ID;
与其检查每个术语的ID和颜色,这就是为什么它对所有术语都适用相同的原因。
尝试此操作(未测试):
<?php
$categories = get_the_category();
$sep = \'\';
foreach ($categories as $cat) {
$the_category_id = $cat->term_id;
if(function_exists(\'rl_color\')){
$rl_category_color = rl_color($the_category_id);
} else {
$rl_category_color = \'#000\'; // maybe a default color?
}
echo $sep . \'<a href="\' . get_category_link($cat->term_id) . \'" class="\' . $cat->slug . \'" title="View all posts in \'. esc_attr($cat->name) . \'" style="background-color:\' . $rl_category_color . \'">\' . $cat->cat_name . \'</a>\';
$sep = \', \';
}
?>