最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - One color to category link depending on category ID

programmeradmin3浏览0评论

I would like to style a category link depending on its ID, for instance, if the category ID is 2, then I want the link to be pink.

I cannot find a way to do the same thing to links. What type of solutions are available? Please be detailed in your reply as my coding knowledge is limited. Thanks a lot :)

I would like to style a category link depending on its ID, for instance, if the category ID is 2, then I want the link to be pink.

I cannot find a way to do the same thing to links. What type of solutions are available? Please be detailed in your reply as my coding knowledge is limited. Thanks a lot :)

Share Improve this question asked Mar 23, 2013 at 16:52 LudoLudo 1 1
  • 1 what category links are you referring to? the ones from a category menu or categories widget? or the one from a post? – Michael Commented Mar 23, 2013 at 18:53
Add a comment  | 

1 Answer 1

Reset to default 0

Open the page which is rendering the category posts, and in the appropriate place (before running the loop) write the following code

<?php
$catid = get_cat_id();
$color = "#222"; //default;
if ($catid == $pinkCategoryId) $color = "#8B0A50";
else if ($catid == $redCategoryId) $color = "#FF0000";
?>

<style type = 'text/css'>
a { color: <?php echo $color;?>; }
</style>

Now adjust the code block above according to your need

You can also use it by category name instead of category id, just change the get_cat_id to get_the_category() which will return the current category name. Then you can perform the rest of the task as is

发布评论

评论列表(0)

  1. 暂无评论