Hi,
I've been using some php code to display time-based, promotional content on my website, which is set to expire on a certain date. Its really useful in the sense that you dont have to sit by your computer to make website updates on the dates specified - you can code your pages well in advance and the scripts automatically switches content over on the defined days.
Anyway, I thought the code might be useful to others so here it is.
Please note, I found parts of the code snippets on other forums/the web and have slightly modified them and mashed them together for my own needs. They're not rocket science but I don't want to claim to have written them myself.
Code to hide content after a certain date:
Code to show alternative content after a certain date:Code:<?php if(mktime() < mktime(0,0,0,07,20,2009)) { ?> Put your current content here that you want to hide after expiry date above. (Note: 07,20,2009 = MONTH, DAY, YEAR) <?php } ?>
Code to show content1 upto a certain date, content2 for a limited time (between 2 defined dates), and content3 after the expiry dateCode:<?php $exp_date = "2009-07-27"; $todays_date = date("Y-m-d"); $today = strtotime($todays_date); $expiration_date = strtotime($exp_date); if ($expiration_date > $today) { ?> <!-- put current content here --> CURRENT (any HTML) <?php } else { ?> <!-- put expired content here --> EXPIRED (any HTML) <?php } ?>
(ideal for promotional offers):
I hope somebody finds it useful.Code:<?php $exp_date = "2009-07-20"; $exp_date2 = "2009-07-27"; $todays_date = date("Y-m-d"); $today = strtotime($todays_date); $expiration_date = strtotime($exp_date); $expiration_date2 = strtotime($exp_date2); if ($expiration_date > $today) { ?> <!-- put pre-promotion week content here --> e.g. - DON'T MISS OUR DISCOUT WEEK - COMING SOON (any HTML) <?php } else if (($expiration_date2 > $today) & ($expiration_date < $today)) { ?> <!-- put promotion week content here --> e.g. - IT'S DISCOUNT WEEK - GRAB YOUR BARGAINS (any HTML) <?php } else { ?> <!-- put expired/post-promotion week content here --> e.g. - PRICES ARE BACK TO NORMAL (any HTML) <?php } ?>



Reply With Quote



Bookmarks