Location: PHPKode > scripts > Calendar > bastianallgeier-calendar-94b7e60/examples/month.php


setlocale(LC_ALL, 'en_US');

// get the year and number of week from the query string and sanitize it
$year  = filter_input(INPUT_GET, 'year', FILTER_VALIDATE_INT);
$month = filter_input(INPUT_GET, 'month', FILTER_VALIDATE_INT);

// initialize the calendar object
$calendar = new calendar();

// get the current month object by year and number of month
$currentMonth = $calendar->month($year, $month);

// get the previous and next month for pagination
$prevMonth = $currentMonth->prev();
$nextMonth = $currentMonth->next();

// generate the URLs for pagination
$prevMonthURL = sprintf('?year=%s&month=%s', $prevMonth->year()->int(), $prevMonth->int());
$nextMonthURL = sprintf('?year=%s&month=%s', $nextMonth->year()->int(), $nextMonth->int());

// set the active tab for the header
$activeTab = 'month';



<section class="month">

    <a class="arrow" href="<?php echo $prevMonthURL ?>">&larr;</a> 
    <?php echo $currentMonth->name() ?> <a href="year.php?year=<?php echo $currentMonth->year()->int() ?>"><?php echo $currentMonth->year()->int() ?></a>
    <a class="arrow" href="<?php echo $nextMonthURL ?>">&rarr;</a>
      <?php foreach($currentMonth->weeks()->first()->days() as $weekDay): ?>
      <th><?php echo $weekDay->shortname() ?></th>
      <?php endforeach ?>
    <?php foreach($currentMonth->weeks(6) as $week): ?>
      <?php foreach($week->days() as $day): ?>
      <td<?php if($day->month() != $currentMonth) echo ' class="inactive"' ?>><?php echo ($day->isToday()) ? '<strong>' . $day->int() . '</strong>' : $day->int() ?></td>
      <?php endforeach ?>  
    <?php endforeach ?>


<?php require('../assets/snippets/footer.php') ?>
Return current item: Calendar