summaryrefslogtreecommitdiff
path: root/event-list.php
diff options
context:
space:
mode:
Diffstat (limited to 'event-list.php')
-rw-r--r--event-list.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/event-list.php b/event-list.php
new file mode 100644
index 0000000..a6780f6
--- /dev/null
+++ b/event-list.php
@@ -0,0 +1,46 @@
+<?php
+/* DISPLAY - front page widget
+ *
+ */
+
+function communievents_event_list($attr) {
+ global $wpdb;
+ global $wp_locale;
+
+ $out = '';
+
+ $table_name = $wpdb->prefix . 'communievents_events';
+ $limit = 10;
+
+ $tz = new DateTimeZone(CommuniApi::TIMEZONE);
+ $now_dt = new DateTime('now', $tz);
+
+ $list = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE %s < end AND official=1 ORDER BY start LIMIT %d",
+ $now_dt->format('Y-m-d H:i:s'), $limit));
+
+ if ($list) {
+ $out .= '<table class="communievents-event-list">';
+
+ foreach ($list as $event) {
+ $start_dt = new DateTime($event->start, $tz);
+
+ $out .= '<tr class="communievents-event-future">';
+ $out .= '<td class="communievents-weekday">' . $wp_locale->get_weekday_abbrev($wp_locale->get_weekday($start_dt->format('w'))) . ', ';
+ $out .= '<td class="communievents-date">' . $start_dt->format('j.') . $wp_locale->get_month_abbrev($wp_locale->get_month($start_dt->format('m')));
+ $out .= '<td class="communievents-time">' . ($event->allday ? '' : $start_dt->format( 'G:i' ));
+ $out .= '<td class="communievents-link">';
+ $out .= '<a href="' . esc_url($event->url) . '">';
+ $out .= $event->title;
+ $out .= '</a>';
+ }
+
+ $out .= '</table>';
+ }
+
+ return $out;
+}
+
+function communievents_setup_event_list() {
+ add_shortcode('communievents-event-list', 'communievents_event_list');
+}
+