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

时间:2013-05-09 04:16:34

标签: php arrays wordpress wp-list-categories

我正在努力实现超越我的PHP知识的somenthing,似乎无法解决它。

我想要做的是为每个类别的wordpress分配一个颜色列表作为一个类。

例如:我的类别是“猫1”,“猫2”和“猫3” 我的颜色是“红色”,“绿色”和“蓝色”

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

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

1 个答案:

答案 0 :(得分:0)

在您的主题中,您可以使用post_class()输出作为帖子类别以及循环中the_category()的输出来获得效果;

http://codex.wordpress.org/Function_Reference/post_class http://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; }

更多here