Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active January 22, 2016 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save srikat/8350989 to your computer and use it in GitHub Desktop.
Save srikat/8350989 to your computer and use it in GitHub Desktop.
Conditional code for different days of a week
<?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';
}
<?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;
<?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