MENU

UDT that outputs the current season

  Previous article Next article  

At our community website I made a header with a changing photo of our village and the surrounding area. I made four folders with photos, one for each season. With a User Defined Tag I read the date and determine what season it is and set it in a Smarty string. With that I change the output of the photo gallery path.
In the CMSMS forum we discussed a similar UDT, I improved the code and will show it to you here.

  How to use

Create a new UDT with the name "season" and the content:

season
date_default_timezone_set('UTC');

$limits = array (
        '/12/21'=>'winter',
        '/09/21'=>'autumn',
        '/06/21'=>'summer',
        '/03/21'=>'spring',
        '/01/01'=>'winter');

foreach ( $limits as $key => $value ) {
        $limit = date('Y') . $key;
        if ( time() >= strtotime($limit) ) return $value;
}

You can use this UDT in your page or template like:

<img src="{uploads_url}/images/{season}.jpg" alt="It is {season}!" />
<div class="{season}"></div>
{Gallery dir="header-photos/{season}" action='showrandom' number='1' template='header'}

  Working example

Code:
<p>The current season is: <b>{season}</b></p>
Output:

The current season is: summer


  Working example




  Show related articles:


  Comment Form

Click here to open the form


  0 Comments

No comments yet...

CMS Made Simple - Tutorials, tips and tricks - CMSMS

UDT that outputs the current season

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.7
  Last updated: 22-11-2017
  Comments: 0
  http://cms.ms/cYoO

Advertisement



Ads help me to help you! Thanks!

Ads help me to help you! Thanks!

Ads help me to help you! Thanks!