Today button in calendar

5 posts by 2 authors in: Forums > CMS Builder
Last Post: October 11, 2019   (RSS)

By MercerDesign - October 1, 2019

Hi, I am using the Zickey Calendar 5 and it is working well but can anyone tell me how I can put in a "Today" button, so when you click it it will take you to todays day, and how can I highlight todays date. Thank you in advance

By MercerDesign - October 10, 2019

Hi, thank you for your help, however I am struggling to find where to put the code in my existing code:

<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
// To start the calendar on Monday instead of Sunday, switch out the next 2 lines
// $startday = $thismonth['wday'];
$startday = $thismonth['wday'] -1;
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>\n";
if($i < $startday) {
echo "<td></td>\n";
}
else {
$day = $i - $startday + 1;
echo "<td class='CalDates'>". $day . "<br />";
// check if there are any events for this day
if (array_key_exists($day, $croscombe_eventsByDay)) {
// list all croscombe_events for this day
foreach ($croscombe_eventsByDay[$day] as $record) {
?> <div id="calFonts">
<h3><?php echo htmlencode($record['title']) ?></h3>
<p><strong><?php echo date("g:i a", strtotime($record['start_date'])) ?></strong></p>
<?php if($record['end_time'] != "0000-00-00 00:00:00") : ?>
<?php echo $record['end_time'] ?>
<?php endif; ?>

<p><?php echo htmlencode($record['location']) ?></p>
<hr>
<?php if($record['description'] != "") : ?>
<a href="/NEW-SITE-MERCER/croscombe<?php echo $record['_link'] ?>">Find out more >></a>
<?php endif; ?>
</div>
<?php
}
}
echo "</td>\n";
}
if(($i % 7) == 6 ) echo "</tr>\n";
}
?>

By daniel - October 10, 2019

Hi MercerDesign,

With your code, you should be able to do something like changing this line:

echo "<td class='CalDates'>". $day . "<br />";

To this:

if ($cMonth == date('n') && $cYear == date('Y') && $date == date('j')) {
  echo "<td class='CalDates today'>". $day . "<br />";
} else {
  echo "<td class='CalDates'>". $day . "<br />";
}

You could then use a ".today" CSS class to change the styling for that day. 

Let me know if that clears it up, or if you have any more questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By MercerDesign - October 11, 2019

Perfect, it works now. THANK YOU