Make the Customizr home slider season based

Compatible with Customizr-Pro

Hi, wouldn’t be cool displaying a different slider on the front page, depending on the season?
That’s what you have to do:

  1. Create 4 sliders and name with the season’s names (lowercase)
  2. In Appearance -> Customize -> Content: home, posts, .. -> Front Page -> Slider Options
    Select a front page slider. You can use the demo slider, or whatever, but select one 😉
  3. In your child-theme functions.php add this snippet:
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;
}

 

Where to copy/paste this code?
Add it to your child-theme functions.php.
Everything you need to know about creating a child theme with Customizr here.

Goodbye and goodluck

12 thoughts on “Make the Customizr home slider season based”

Comments are closed.