Last active
August 29, 2015 14:12
-
-
Save eri-trabiccolo/fecce087a1084504ce4f to your computer and use it in GitHub Desktop.
Automatic changing of slider depending on season
This file contains 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
/* source: http://www.geekpedia.com/code152_Get-The-Current-Season.html */ | |
function get_season() { | |
$season_slider = array('/12/21'=>'winter', | |
'/09/21'=>'autumn', | |
'/06/21'=>'summer', | |
'/03/21'=>'spring', | |
'/01/01'=>'winter'); //this needed to be at Jan 1st | |
foreach ($season_slider as $key => $value) // Loop through the season dates | |
{ | |
$season_date = date("Y").$key; | |
if (strtotime("now") > strtotime($season_date)) // If we're after the date of the starting season | |
{ | |
return $value; | |
} | |
} | |
} | |
add_filter('tc_slider_name_id', 'season_sliders'); | |
function season_sliders($slider_name_id){ | |
$sliders = tc__f('__get_option' , 'tc_sliders'); | |
// if there isn't a slider with a season name fallback on the home slider | |
if ( tc__f('__is_home') && | |
isset( $sliders[get_season()] ) | |
) | |
return get_season(); | |
return $slider_name_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment