思路是用别名来定义一个CSS,然后给当前分类下的别名定义一个CSS样式,代码如下
<style type=”text/css”>
<!–
.<?php $cat = get_category($cat);echo $cat->slug;?>{ color:#9B0E05!important}
–>
</style>
上面是CSS部分,下面是代码:
<?php $categories = get_categories(‘hide_empty=0&parent=13&orderby=id’); foreach ($categories as $cat) { $catid = $cat->cat_ID; query_posts(“showposts=100&cat=$catid”); ?>
<li>
<div class=”dl_box”> <span class=”classification-span”> <a href=”<?php echo get_category_link($catid);?>” class=”classification classification_click”>
<div class=”goods-family”><?php $cat_des = category_description(); echo str_replace(array(“<p>”,””,”</p>”, “r”, “n”),””,$cat_des);?><span></span></div>
<p class=”<?php $cat = get_category($cat);echo $cat->slug;?>
“>
<?php single_cat_title(); ?>
</p>
</a> <span class=”common-spirite-pc”></span> </span>
<dl style=”display: none;”>
<?php while (have_posts()) : the_post(); ?>
<dd><a href=”<?php the_permalink() ?>”><span class=”dot “></span>
<?php the_title(); ?>
</a></dd>
<?php endwhile; ?>
</dl>
</div>
</li>
<?php } ?>
<?php wp_reset_query(); ?>