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: spring


  Working example



Buy Me A Coffee


  Show related articles:


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  0 Comments

No comments yet...

Buy Me A Coffee

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.19
  Last updated: 10-06-2019
  Comments: 0
  http://cms.ms/cYoO


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!