Events Made Easy › Forums › How do I … › A calendar view for a whole year
- This topic has 6 replies, 2 voices, and was last updated 6 years, 10 months ago by Anonymous.
-
AuthorPosts
-
Tue 23 Jan 2018 at 08:31 #57396AnonymousInactive
Hello everyone,
first I would like to thank Franky for his marvellous work. EME is a fantastic software, after testing it for only two weeks or so, I really love it.
I wonder if someone has already done a calendar view for a whole year. Of cause you could set something up with twelve small calendars, but there will always be a layout problem because of different row numbers (four or five) between the monthly views. So I would like to have a grid of twelve rows and thirty-one columns in the style of the small calendar views – how could this be done, or is it already possible and I missed it?
Greetings
MathiasTue 23 Jan 2018 at 09:42 #57397FrankyKeymasterEither do that in a table (they are not that evil), so your layout will be ok (or div’s).
Or use [eme_events] with a layout of your liking …Wed 24 Jan 2018 at 15:50 #57403AnonymousInactiveI did it – quick and dirty and in a table ;D
Its up and running in WordPress on my local webserver, now I am looking forward for testing it online. In case it should be usefull for anybody else, and if it is fine with Franky, here is the code without warranty or further support. If you find any errors or better solutions, I would be very interested to read your feedback and suggestions.
PHP:
$now=getdate(); $current_year=$now['year']; $today=sprintf('%04d-%02d-%02d', $now['year'], $now['mon'], $now['mday']); $months=array('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'); // year row echo '<table class="calendar">'; echo '<th colspan="32" class="year">'.$current_year.'</th>'; // year row // month rows $month=''; for ($row=1; $row<=12; $row++) { echo '<tr>'; echo '<td class="month">'.$months[$month].'</td>'; $month_days=date('t',mktime(0,0,0,$row,1,$current_year)); // day cells $day=''; for ($column=1; $column<=31; $column++) { $dotw=date('w',mktime(0,0,0,$row,$column,$current_year)); if ($column<=$month_days) { $day=$column; if ($dotw>0 AND $dotw<6) { $dayclass="wday"; } if ($dotw<1 OR $dotw>5) { $dayclass="fday"; } $currentcell = sprintf('%04d-%02d-%02d', $current_year, $row, $column); if ($currentcell==$today) { $dayclass="today"; } if (eme_are_events_available(sprintf('%04d-%02d-%02d', $current_year, $row, $column))) { $eventclass="event"; } else { $eventclass="noevent"; } } else { $day=''; $dayclass="noday"; } echo '<td class="'.$eventclass.'">'; echo '<span class="'.$dayclass.'">'.$day.'</span>'; echo '</td>'; } // day cells echo '</tr>'; $month++; } // month rows echo '</table>';
CSS:
.calendar .year{ color:#333333; } .calendar .noday{ } .calendar .fday{ color:#333333; font-weight: bold; } .calendar .today{ text-decoration-line: underline; } .calendar .event{ background-color:#FD7E29; } .calendar .noevent{ background-color:#eeeeee; }
Regards to Franky
MathiasWed 24 Jan 2018 at 16:19 #57405FrankyKeymasterThat’s not really a calendar 🙂
I’d just do this in a regular page:[eme_events scope=this_year limit=0]
and use a template (using template_id/header/footer) to put it into a table if desired. Adding the option showperiod=monthly (or yearly) shows the month etc …
Wed 24 Jan 2018 at 16:38 #57407AnonymousInactiveIt is not?
Why?Wed 24 Jan 2018 at 17:16 #57408FrankyKeymasterCan you go back a year/forth? Well, anyway, if you use: feel free to post a demo-link here, that will be easier for people to visualize.
Wed 24 Jan 2018 at 19:35 #57410AnonymousInactiveAha, ok: well, this is a calendar for the current year, of cause!
But there is also an option for browsing between years.
a. Replace
$current_year=$now['year'];
with
if (!isset($_GET['current_year'])) { $current_year=$now['year']; } else { $current_year=$_GET['current_year']; }
b. Add the URL of the page which contains this script, for example
$calendar_url=$_SERVER['PHP_SELF'].'/yearly-calendar/*(or whatever)*//';
on top/before the first ‘echo’ command.c. Replace
echo '<th colspan="32" class="year">'.$current_year.'</th>';
with
echo '<th colspan="32" class="year"> <a href="'.$calendar_url.'?current_year='.($current_year-1).'">< '.($current_year-1).'</a> | '.$current_year.' | <a href="'.$calendar_url.'?current_year='.($current_year+1).'">'.($current_year+1).' ></a> </th>';
d. There is already a small bug, replace
$month='';
with
$month=0;
Voilà. I hope, it is now a real calendar 🙂 , and will post a link if the website I am currently working on is online.
Best regards!
-
AuthorPosts
- The forum ‘How do I …’ is closed to new topics and replies.