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