Format font dynamically – what am I doing wrong?
-
Hi,
I’m trying to format a custom event type based on a custom field.
I have a list of events where the custom ‘type’ feild can be one of ‘Unavailable Date’, ‘Gig Date’ or ‘Rehearsal Date’.
I want the post title font to be a different color based on the ‘type’ field.This is what i’ve got…
while($gigsPosts->have_posts()) { $gigsPosts->the_post(); ?> <li > <?php $colorOption = get_field('type') ; if( $colorOption = "Unavailable Date"){$color = "red";} elseif ( $colorOption = "Gig Date"){$color = "gray";} elseif ($colorOption = "Rehearsal Date"){$color = "Blue";} ?> <a href="<?php the_permalink() ?>" > <div class="date"> <p class="day"><?php $eventDate = new DateTime(get_field('date')); echo $eventDate->format('d')?></p> <p class="month"><?php echo $eventDate->format('M')?></p> </div> <div class="item-info-container"> <h1 style="color:<?php echo $color; ?>"><?php the_title()?></h1> <p class="item-description"> <?php echo get_field('description')?> </p> </div> </a> </li> <?php } ?> </ul> </div>
With the code as it is, all of my post titles are showing in red.
If I echo out $color I get ‘red’ for each post (test posts with a mix of ‘type’ categories’.
If I echo out get_field(‘type’) I get ‘Array’…so presumably the if statement is returning the first array item for each entry?any help on this would be great – I’m on the verge of understanding this ??
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Format font dynamically – what am I doing wrong?’ is closed to new replies.