user defined tag not working [solved]

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
babel
Forum Members
Forum Members
Posts: 149
Joined: Fri Oct 19, 2012 8:58 pm

user defined tag not working [solved]

Post by babel »

I have this udf tag

Code: Select all

function seizoen() {
    date_default_timezone_set('UTC');
   $limits=array(
   '/12/21'=>'<img src="images/winter.jpg"/>',
   '/09/21'=>'<img src="images/herfst.png" alt="moeder met kind in herfstlandschap in de bergen"/>',
   '/06/21'=>'<img src="images/zomer.jpg"/>',
   '/03/21'=>'<img src="images/lente.jpg" alt="wandelaar met rugzak"/>',
   '/12/31'=>'<img src="images/winter.jpg"/>');
   foreach($limits AS $key => $value) {
       $limit=date("Y").$key;
       if(strtotime("now")>strtotime($limit)) {
           return $value;
       }
   }
}
 
echo seizoen();
The purpose was to show another background image according to the season. Worked fine, but not anymore. Nothing to my knowlodge has changed.
In the template you find <div id="bg_index">{img_seizoen}</div>
It's for cms ms version 1.11.9.
The website ishttp://www.slee-buitensport.nl/index.php
Can somebody tell me what is wrong? Just for the sake. My knowlodge of PHP is very limited.
Thanks for reading.
Last edited by babel on Thu Jan 08, 2015 5:01 pm, edited 1 time in total.
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: user defined tag not working

Post by Jeff »

According to that logic, none of them will be selected because none of the "limits" are in the past.

If I understand the pattern/logic, the last limit should be /01/01 instead of /12/31.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: user defined tag not working

Post by Rolf »

Where did you find the original code?
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
babel
Forum Members
Forum Members
Posts: 149
Joined: Fri Oct 19, 2012 8:58 pm

Re: user defined tag not working

Post by babel »

Thanks Jeff for the help. Can't remember where I found the code, but your solution worked. Great.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: user defined tag not working [solved]

Post by Rolf »

I rewrote the UDT a bit. It is more clean this way...

UDT named "season"

Code: Select all

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;
}
In page or template:

Code: Select all

<img src="{uploads_url}/images/{season}.jpg" alt="{season}" />
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: user defined tag not working [solved]

Post by calguy1000 »

instead of strtotime('now') just use time()
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “The Lounge”