-
-
Save srikat/8350989 to your computer and use it in GitHub Desktop.
Conditional code for different days of a week
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dates = array("Sunday", | |
"Monday", | |
"Tuesday", | |
"Wednesday", | |
"Thursday", | |
"Friday", | |
"Saturday" | |
); | |
// This echos today's date | |
// echo $dates[date("w")]; | |
if ( $dates[date("w")] == "Saturday" || $dates[date("w")] == "Sunday" ) { | |
echo 'Yes, It is weekend!'; | |
} | |
else { | |
echo 'Oh no, back to work'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dates = array("Sunday", | |
"Monday", | |
"Tuesday", | |
"Wednesday", | |
"Thursday", | |
"Friday", | |
"Saturday" | |
); | |
$day = $dates[date("w")]; | |
switch ($day) { | |
case "Sunday": | |
$image_of_day = '<img src="' . get_stylesheet_directory_uri() . '/images/offer-box/weekend.jpg" />'; | |
break; | |
case "Monday": | |
$image_of_day = '<img src="' . get_stylesheet_directory_uri() . '/images/offer-box/monday.jpg" />'; | |
break; | |
case "Tuesday": | |
$image_of_day = '<img src="' . get_stylesheet_directory_uri() . '/images/offer-box/tuesday.jpg" />'; | |
break; | |
case "Wednesday": | |
$image_of_day = '<img src="' . get_stylesheet_directory_uri() . '/images/offer-box/wednesday.jpg" />'; | |
break; | |
case "Thursday": | |
$image_of_day = '<img src="' . get_stylesheet_directory_uri() . '/images/offer-box/thursday.jpg" />'; | |
break; | |
case "Friday": | |
$image_of_day = '<img src="' . get_stylesheet_directory_uri() . '/images/offer-box/friday.jpg" />'; | |
break; | |
case "Saturday": | |
$image_of_day = '<img src="' . get_stylesheet_directory_uri() . '/images/offer-box/weekend.jpg" />'; | |
break; | |
} | |
echo $image_of_day; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$image_of_day_file = in_array( date( 'l' ), ['Saturday', 'Sunday'] ) ? 'weekend' : strtolower( date( 'l' ) ); | |
$image_url = get_stylesheet_directory_uri() . '/images/offer-box/' . $image_of_day_file . '.jpg'; | |
echo '<img src="' . esc_url( $image_url ) . '" alt="" />'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment