Answer the question
In order to leave comments, you need to log in
How to display different color of displayed categories in Wordpress?
The category name looks like this:
<a class="post-category-color-text" style="background:#36c942" href="#">
<?php $category = get_the_category(); echo $category[0]->cat_name; ?></a>
Answer the question
In order to leave comments, you need to log in
You can add a class that is equal to the category slug and css for each class has its own background.
<?php $category = get_the_category(); ?>
<a class="post-category-color-text <?php echo $category[0]->slug; ?>" style="background:#36c942" href="#">
<?php echo $category[0]->cat_name; ?>
</a>
/* Пример */
/* Для slug = animals */
.animals{
background: #eee;
}
/* Для slug = birds */
.birds{
background: #ccc;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question