UDT that outputs the current season

  Previous article Next article  

UDT that outputs the current season

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.2
  Last updated: 21-03-2015
  Comments: 0

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



A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  0 Comments

No comments yet...

CMS Made Simple 2.2.2 - Tutorials, tips and tricks - CMSMS 2.2.2

UDT that outputs the current season

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.2
  Last updated: 21-03-2015
  Comments: 0

A2 Webhosting CMS Made Simple