Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-02-21 21:27:19

matgorb
Member
Registered: 2005-06-12
Posts: 31

[Resolved] Countdown using a custom field

I use to be able to do a countdown using an end-date store in a custom field, however since 4.0.4 it seems that this is not possible anymore as the txp tag in the php code doesn’t seem to resolve properly anymore.
Any idea of what I could do, or what I do wrong.

<txp:custom_field name="end_date" />
<txp:php>
$fin = strtotime('<txp:custom_field name="end_date" />');//$fin is end-date
//format année/mois/jour (year/month/day)
$hui = time ();//$hui is today
if ($fin >= $hui)
{
    $difference = ($fin-$hui);
    $jours = (int) ($difference/86400);//days
    $heures = (int) (($difference - ($jours*86400))/3600);//hours
    $minutes = (int) (($difference - ($jours*86400) - ($heures*3600))/60);//minutes
}
echo "<span class=\"invisible\">Fin de la vente : </span>\n";
printf(" %02d ",$jours);
echo "<span class=\"invisible\">jours(s) </span>\n";
printf(" %02d ", $heures);
echo "<span class=\"invisible\">heures(s) </span>\n";
printf(" %02d ", $minutes);
echo "<span class=\"invisible\">minutes(s)</span>";
</txp:php>

Last edited by matgorb (2007-02-22 09:15:17)

Offline

#2 2007-02-22 05:57:08

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: [Resolved] Countdown using a custom field

If it worked before, it was because of a fluke (it shouldn’t have worked).

<txp:custom_field name="end_date" />

<txp:php>
//$fin is end-date
//format année/mois/jour (year/month/day)
$fin = strtotime(custom_field(array('name' => 'end_date')));

//$hui is today
$hui = time();

if ($fin > $hui)
{
	$diff = ($fin - $hui);

	// days
	$jours = (int) ( $diff / 86400 );

	// hours
	$heures = (int) ( ($diff - ($jours * 86400)) / 3600 );

	// minutes
	$minutes = (int) ( ($diff - ($jours * 86400) - ($heures * 3600)) / 60 );


	echo '<span class="invisible">Fin de la vente:</span> '.
		$jours.' <span class="invisible">jours(s)</span> '.
		$heures.' <span class="invisible">heures(s)</span> '.
		$minutes.' <span class="invisible">minutes(s)</span>';
}
</txp:php>

:)

Last edited by Mary (2007-02-22 05:57:21)

Offline

#3 2007-02-22 09:17:29

matgorb
Member
Registered: 2005-06-12
Posts: 31

Re: [Resolved] Countdown using a custom field

Thanks Mary.
What’s the easiest way to dig for those nice functions?

Offline

#4 2007-02-22 09:47:43

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: [Resolved] Countdown using a custom field

textpattern/publish/taghandlers.php.

Offline

Board footer

Powered by FluxBB