将Wordpress类别数组与另一个组合


Combine Wordpress categories array with another one

我正在尝试实现一些超出我的php知识,似乎无法绕过它。

我要做的是为wordpress的每个类别指定一个颜色列表作为一个类。

例如:我的分类是"猫1","猫2"answers"猫3"我的颜色是"红","绿"answers"蓝"

当我打印get_categories时,每个类别都应该有一个单独的类和样式,因此cat 1将获得红色背景,cat 2将获得绿色背景,cat 3将获得蓝色背景。

更重要的是,我希望能够添加很多颜色(例如25),如果有10个类别,那么只使用前10种颜色

在您的主题中,您可以将post_class()输出与循环中的the_category()输出一起使用,以获得该效果;

http://codex.wordpress.org/Function_Reference/post_classhttp://codex.wordpress.org/Function_Reference/the_category

示例(为简单起见,假设每个帖子只有一个类别,需要在循环内):

<div <?php post_class(); ?>>
<h3 class="entry-title"><span class="media-type"><?php the_category(' '); ?></span><a href="<?php the_permalink(); ?><?php the_title(); ?></a></h3>
<!--more post output-->
</div>

和style.css:

.category-cat1 span a { color: green; }
.category-othercatname span a { color: orange; }

这里