Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » How do I…?
  3. » If date?

#1 2010-06-29 23:09:36

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

If date?

Dear TXPers,

Can anyone recommend a plugin for testing dates? Something along the lines of:

<txp:if_date date="december">
	<p>'Tis the season to be jolly.</p>
<txp:else />
	<p>Not Christmas yet.</p>
</txp:if_date>

I can only find plugins that deal with article posting dates.

Offline

#2 2010-06-29 23:29:06

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: If date?

Does it have to be a plugin? I’d go for something like this + variable/if_variable.

Offline

#3 2010-06-29 23:38:11

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: If date?

Els wrote:

Does it have to be a plugin? I’d go for something like this + variable/if_variable.

Thanks Els, much obliged. Nope, it doesn’t have to be a plugin. I’ll have a look at your suggestion.

Offline

#4 2010-06-29 23:42:58

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: If date?

Or of course smd_if, see my post above the one I linked to.

Offline

#5 2010-06-30 04:26:49

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: If date?

In case of simple month checking you can use this (look date ref):

<txp:variable name="month"><txp:php>echo date("F");</txp:php></txp:variable>
<txp:if_variable name="month" value="December"> <!-- <<< not sure about case-sensetive checking - date("F") returns December, not december-->
	<p>'Tis the season to be jolly.</p>
<txp:else />
	<p>Not Christmas yet.</p>
</txp:if_variable>

More complex checkings can be done with smd_if


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#6 2010-07-22 19:58:21

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: If date?

Thanks Els & Victor.

Just for the record, here’s what I’m using:

<txp:php>
 	$seasons = array('1221' => 'summer', '0921' => 'spring', '0621' => 'winter', '0321' => 'autumn', '0000' => 'summer');
	foreach($seasons as $date => $season) if (strftime('%m%d') >= $date) break;
	$GLOBALS['variable']['season'] = $season;
</txp:php>

It’s basically Ruud’s code but I’ve adjusted the dates to cater for the topsy-turvy seasons on the bottom of the world & shoved the result into a TXP variable.

Edit: and strftime('%m%e') changed to be strftime('%m%d')

Last edited by gomedia (2010-10-06 08:44:23)

Offline

  1. Index
  2. » How do I…?
  3. » If date?

Board footer

Powered by FluxBB