I am trying to style category names with different colours.
Here is my PHP:
<?php
foreach((get_the_category()) as $category) {
if (is_category('5') ) {
echo '<a class="featured" href="' . get_category_link( $category->cat_ID ) . '">' . $category->cat_name . '</a>';}
else {
echo '<a href="' . get_category_link( $category->cat_ID ) . '">' . $category->cat_name . '</a> ';}
}
?>
It is not returning errors, but it is not working either…
What am I doing wrong?
Here is the page I’m working on:
http://216.172.178.12/~saracimi/eng/
and the snippet of code is relative to the rectangular boxes at the center of the page.
Thanks a bunch!
is_category will return true when you are on that category archive. you need to check the category id so try: