admin管理员组文章数量:1389758
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
1 Answer
Reset to default 0Open 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
本文标签: categoriesOne color to category link depending on category ID
版权声明:本文标题:categories - One color to category link depending on category ID 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744669211a2618721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论