Created
October 22, 2010 09:42
-
-
Save FutureMedia/640249 to your computer and use it in GitHub Desktop.
Events Calendar (http://podscms.org/qna/questions/823/graphical-calendar)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#calendar_div table { | |
border-collapse:collapse; | |
} | |
#cal_table_list td { | |
vertical-align:top; | |
padding:4px; | |
} | |
#cal_table_list td { | |
border-bottom:1px dotted #BBB; | |
} | |
#cal_table_list .wknd { | |
background:#DDD; | |
} | |
#cal_head td { | |
border-bottom:1px solid #666; | |
padding:1em 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Here's the complete customised pod page for a working event calendar, based on input from the three other lovely people in this thread. For my purposes, it was most useful to have each day with its own row rather than a traditional calendar with weeks in rows, because I wanted to list the titles of the events on the days they're happening, and this way give me more room and greater clarity. But if you prefer weeks in rows, just revert to jbrickman's format. Some of this can likely be tidied up further, I'm not an expert - but it'll be a useful working starting point for further refinement and customisation. | |
*/ | |
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); | |
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); | |
$cMonth = $_REQUEST["month"]; | |
$cYear = $_REQUEST["year"]; | |
$prev_year = $cYear; | |
$next_year = $cYear; | |
$prev_month = $cMonth-1; | |
$next_month = $cMonth+1; | |
if ($prev_month == 0 ) { | |
$prev_month = 12; | |
$prev_year = $cYear - 1; | |
} | |
if ($next_month == 13 ) { | |
$next_month = 1; | |
$next_year = $cYear + 1; | |
} ?> | |
<div id="calendar_div" name="calendar_div"> | |
<table id="cal_table" width="100%"> | |
<tr align="center"> | |
<td id="cal_head"> | |
<table width="100%"> | |
<tr> | |
<td align="left" width="25%"><a href="<?php echo "?month=". $prev_month . "&year=" . $prev_year; ?>">Previous</a></td> | |
<td align="center" width="50%"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td> | |
<td align="right" width="25%"><a href="<?php echo "?month=". $next_month . "&year=" . $next_year; ?>">Next</a></td> | |
</tr> | |
</table> | |
</td> | |
</tr> | |
<tr> | |
<td align="center"> | |
<table id="cal_table_list" width="100%"> | |
<?php | |
$timestamp = mktime(0,0,0,$cMonth,1,$cYear); | |
$maxday = date("t",$timestamp); | |
$thismonth = getdate($timestamp); | |
$startday = $thismonth['wday']; | |
$Record = new Pod('event'); | |
$max_events = 500; | |
$where = "MONTH(t.start) = '$cMonth' AND YEAR(t.start) = '$cYear'"; // start is the name of my date column | |
$Record->findRecords('start ASC', $max_events, $where); | |
$month_days = range(1, date("t", mktime(0,0,0,$cMonth,1,$cYear))); | |
$day_events = array_fill_keys($month_days, array()); | |
while($Record->fetchRecord()) { | |
$event_day = date("j", strtotime($Record->get_field('start'))); | |
$day_events[$event_day][] = $Record->data; | |
} | |
$weekday = Array("Su","Mo","Tu","We","Th","Fr","Sa"); | |
$weekend = Array("wknd","wk","wk","wk","wk","wk","wknd"); // so you can style weekends differently to weekdays | |
for ($i=0; $i<($maxday+$startday); $i++) { | |
if($i < $startday) {} | |
else { | |
$date = ($i - $startday + 1); | |
$out = "<tr><td width='25' class='".$weekend[$i % 7]."'><strong>".$weekday[$i % 7]."</strong></td><td width='25' class='".$weekend[$i % 7]."' align='right'>". $date . "</td><td class='".$weekend[$i % 7]."'>"; // each day has its own row | |
foreach ($day_events[$date] as $day) { $out .= "<a href='/en/events/".$day['slug']."'>".$day['name']."</a><br/>\n"; }; // each event is linked to a dedicated page. Make sure you create a corresponding pod page (in my case en/events/*) | |
echo $out . "</td></tr>\n"; | |
} | |
} | |
?> | |
</table> | |
</td> | |
</tr> | |
</table> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment