![]() |
PHP Code in template to use date function?
In a template is it possible to replace the code like the following examples to use a date function:
<li> <a href="https://www.usapolicesupply.com/help.php?"><img src="{$AltSkinDir}/custom/welcome/promotions/image_slider/images/operator.jpg" alt="" /></a> <p class="flex-caption">We have access to over 120,000 products.</p> </li> <li> <a href="http://www.usapolicesupply.com/breast-cancer-awareness/"><img src="{$AltSkinDir}/custom/welcome/promotions/image_slider/images/bcaware.jpg" alt="" /></a> <p class="flex-caption">October is Breast Cancer Awareness Month</p> </li> with PHP code like this: // Macmillan Cancertalk week (21-25 Jan) if ((date('m') == 01) && (date('d') >= 21) || (date('m') == 01) && (date('d') <= 23)) { echo "<img src=\"images/ribbons/cancertalk.gif\" height=\"145\" width=\"175\" alt=\"Macmillan Cancertalk\" /><br /><h6 class=\"awareness\">Macmillan Cancertalk Week <span class=\"morelink\"><a href=\"the-bookstall-cancer-links-and-resources.php\">more...</a></span></h6>"; } // Macmillan Cancertalk week (21-25 Jan) and Cervical Cancer Awareness Week (24-30 Jan) else if ((date('m') == 01) && (date('d') == 24)) { echo "<img src=\"images/ribbons/macmillan_cervical.gif\" height=\"145\" width=\"175\" alt=\"Macmillan Cancertalk and white and teal awareness ribbons\" /><br /><h6 class=\"awareness\">Macmillan Cancertalk Week & Cervical Cancer Awareness Week <span class=\"morelink\"><a href=\"the-bookstall-cancer-links-and-resources.php\">more...</a></span></h6>"; } |
Re: PHP Code in template to use date function?
Yes, but you want to use smarty code in your template.
http://www.smarty.net/docsv2/en/language.modifier.date.format.tpl Examples: Code:
<p>{$smarty.now|date_format:$config.Appearance.date_format}</p> 11-04-2013 Monday November 2013 |
Re: PHP Code in template to use date function?
Am I going in the right direct with this?
{if $smarty.now|date_format:%A eq 'Dec'} Welcome Sir. {elseif $smarty.now|date_format:%A <> 'Dec'} Welcome Ma'am. {else} Welcome, whatever you are. {/if} |
Re: PHP Code in template to use date function?
Quote:
Second, you don't usually make two comparisons at once. You have less than/greater than, it would need to be is variable less than or is variable greater than. I don;t see why you need the else if. Just say If = Dec do this else do this. If it is not december the else would fire. |
Re: PHP Code in template to use date function?
1 Attachment(s)
Here we go, tried to make it easy and spelled out for everyone to grasp completely. I also attached the code in a text file so you could save it and reference later easily.
Code:
<p>What is today's date smarty? <b>{$smarty.now|date_format:$config.Appearance.date_format}</b></p> What is today's date smarty? 11-12-2013 What month is it smarty? November What day of the month is it smarty? 12 What day of the week is it smarty? Tuesday What year is it smarty? 2013 Is it November smarty? Yes Is it December smarty? No Is it November 1st-9th smarty? No Is it November 10th-20th smarty? Yes Is it December 2nd-10th smarty? No |
Re: PHP Code in template to use date function?
Thank you totaltec (Mike)
I tried what you sent and it worked great and I now understand the concept. Thanks JEC |
All times are GMT -8. The time now is 06:55 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.