Login | Sign up | Toll-Free: 1-800-752-0455
 
 

Forum

 

1 posts by 1 authors in: Forums > CMS Builder Community
Last Post: September 22, 2014

Here's a Countdown to Event if the date is greater than now, which uses jQuery and provides an active countdown without the need for the page to refresh. Hope anyone who needs this finds it useful. See the URL to download the files you'll need for the jQuery function.

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  // load viewer library
  $libraryPath = 'cmsBuilder/lib/viewer_functions.php';
  $dirsToCheck = array('/home/server/html/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
  
  // load records
  list($eventsRecords, $eventsMetaData) = getRecords(array(
    'tableName'   => 'events',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $eventsRecord = @$eventsRecords[0]; // get first record
?>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Countdown to Event</title>

<style type="text/css">
#countdown {
font-family:"Gill Sans", "Gill Sans MT", "Myriad Pro", "DejaVu Sans Condensed", Helvetica, Arial, sans-serif;
font-style:italic;
font-weight:bold;
font-size:28px;
}
</style>

<script src="jquery.1.11.0.js" type="text/javascript"></script>
<script src="jquery.countdown.js" type="text/javascript">
// download jquery.countdown.js here: http://hilios.github.io/jQuery.countdown/
</script>

</head>
<body>

<div id="countdown"></div>
<div class="clear-both"></div>
<script type="text/javascript">
$("#countdown")
//.countdown("2015/01/01", function(event) {
.countdown("<?php echo $eventsRecord['date'] ?>", function(event) {
$(this).text(
event.strftime('%D days %H:%M:%S')
);
});
</script>
</body>
</html>

Cheers, Zicky