Today button in calendar

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

By daniel - October 9, 2019

Hi MercerDesign,

The calendar page by default shows the current month, so you can likely just link to the main calendar URL to get to "Today"

From what I can see there's no standard way to "highlight" a specific day, so you'll need to figure out how you want to change the CSS (style attribute, class, etc.). You can use the following in the calendar loop to check if it's listing today:

if ($cMonth == date('n') && $cYear == date('Y') && $date == date('j')) {
 // your code
}

This can the calendar loop below the line with "$day=$i-$startday+1;"

Let me know if that helps get this done, or if you have any questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

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