Using the_date() in php if elseif else statements
-
So this is what I’m trying to do:
Change the css background-color of a div that surrounds my date (I have it all nice and fancy ?? ) depending on the month that the post was written. I am attempting to accomplish this by using the_date within a series of if elseif statements and depending on what the_date(‘m’) outputs suchas 11 then the color for november posts will be #123456. Here’s my code:
<?php /*This is php code to change the background color of the meta circle of a post depending on the month*/ /*setting $monthColor equal to the numerical month value */ $month = the_date("m", FALSE); if ($month == "11"){ echo "aklsjdflfjasdlkjflskjdflkasjdf"; }else{ echo "AKSJDLKJDFLKJSDLKFJLDS"; } if ($month == '1') { $monthColor = "#5E7CFF"; } elseif ($month == '2') { $monthColor = "#FFD06F"; } elseif ($month == '3') { $monthColor = "#55B541"; } elseif ($month == '4') { $monthColor = "#B24D2E"; } elseif ($month == '5') { $monthColor = "#528CB5"; } elseif ($month == '6') { $monthColor = "#96B523"; } elseif ($month == '7') { $monthColor = "#630907"; } elseif ($month == '8') { $monthColor = "#23634B"; } elseif ($month == '9') { $monthColor = "#0B4B63"; } elseif ($month == '10') { $monthColor = "#634C20"; } elseif ($month == "11") { $monthColor == "#F0CF44"; } elseif ($month == '12') { $monthColor = "#42BDF0"; } else { $monthColor = "#000000"; } echo $monthColor; ?>
Here’s the code that I’m using and is working (using the else statement from the above code to display black):
<div class="posts_Date" style="background-color:<?php echo($monthColor); ?>;">
Any help with this would be much appreciated!!! ??
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Using the_date() in php if elseif else statements’ is closed to new replies.