Search the Community
Showing results for tags 'countdown'.
-
A jquery countdown lib is used. Add a date field of your desired template which want to display a countdown widget. I added following code on a event template <?php // convert a php unix timestamp to a javascript datetime format $js_datetime = $page->end_date * 1000; $today = date("U"); $end_date = date('d M Y', $page->end_date); $out = ''; $out = "{$page->body}<br/>"; $out .= "Event ending date: {$end_date}<br/>"; if ($today > $page->end_date) $out .= "<h3>Event is ended.</h3>"; else { $js = ''; $js .= "<script src='{$config->urls->templates}assets/js/jquery.plugin.js'></script>\r\n"; $js .= "<script src='{$config->urls->templates}assets/js/jquery.countdown.js'></script>\r\n"; $js .= "<script>$(function(){endDay = new Date({$js_datetime});$('#Countdown-widget').countdown({until: endDay});});</script>"; $out .= "<div id='Countdown-widget' class='clearfix'></div>"; } $page->body = $out; include('./main.php'); In the main.php output file, echo the $js variable, something like <?php if ($js) echo $js; ?> Some screenshots Usage: With this minimal bare bone code, you could extend and add your functionality. For example, build a groupon like time limited group order page, an online event registration form