I am trying to set up my blog so that there are different colors for 2 different categories, however, if there is a post that is tagged with neither of these 2 categories I want it to default to green.
Here is my code:
<?php if ( in_category( 'News' )) : ?>
<div class="green">
<?php elseif ( in_category('Blog')) : ?>
<div class="orange">
<?php endif; ?>
So basically I want to change it so that if the post isn’t in the “News” or the “Blog” category, it will just default to the “green” class.
Thanks in advance!
You should familiarize yourself with PHP, but if you want a default color ( assuming the code below already works ) you could do:
I’d suggest you use
post_class
for this. The following goes into yourfunctions.php
:Your div now looks like this:
which output some thing like:
the styling is done via CSS as always.