[plugin: Event Calendar 3] custom templating function
-
Hi,
I wanted to share a little experience with the Event Calendar 3 plugin. I was disappointed that this plugin doesn’t provide much theming possibilities. For instance it doesn’t provide the possibility to display the contents of custom fields belonging to events-posts.
So I created my own version of the
ec3_get_events()
function as found in the plugin’stemplate-functions.php
. This function was saved in my theme’sfunctions.php
file and now I can list all my custom fields within the calendar sidebar widget.My new function is allmost similar to the oiginal but it the difference is that it retrieves more content and instead of a unordered list the output is themed in a table (a personal need).
So here’s my custom function:
function ec3_get_events2( $limit, $template_event=EC3_DEFAULT_TEMPLATE_EVENT, $template_day =EC3_DEFAULT_TEMPLATE_DAY, $date_format =EC3_DEFAULT_DATE_FORMAT, $template_month=EC3_DEFAULT_TEMPLATE_MONTH, $month_format =EC3_DEFAULT_MONTH_FORMAT) { if(!ec3_check_installed(__('Upcoming Events','ec3'))) return; global $ec3,$wpdb,$wp_version; // Parse $limit: // NUMBER - limits number of posts // NUMBER days - next NUMBER of days if(empty($limit)) { $limit_numposts='LIMIT 5'; } elseif(preg_match('/^ *([0-9]+) *d(ays?)?/',$limit,$matches)) { $secs=intval($matches[1])*24*3600; $and_before="AND start<='".ec3_strftime('%Y-%m-%d',time()+$secs)."'"; } elseif(intval($limit)<1) { $limit_numposts='LIMIT 5'; } else { $limit_numposts='LIMIT '.intval($limit); } if(!$date_format) $date_format=get_option('date_format'); // Find the upcoming events. $calendar_entries = $wpdb->get_results( "SELECT DISTINCT p.id AS id, post_title, start, u.$ec3->wp_user_nicename AS author, allday FROM $ec3->schedule s LEFT JOIN $wpdb->posts p ON s.post_id=p.id LEFT JOIN $wpdb->users u ON p.post_author = u.id WHERE p.post_status='publish' AND end>='$ec3->today' $and_before ORDER BY start $limit_numposts" ); echo "<table id=\"calendar_table\"> <tr><td>datum:</td><td>organisator:</td><td>bijeenkomst:</td><td>locatie:</td><td>wat:</td><td>inschrijving?</td></tr>"; echo "<!-- Generated by Event Calendar v$ec3->version -->\n"; if($calendar_entries) { $time_format=get_option('time_format'); $current_month=false; $current_date=false; $data=array(); foreach($calendar_entries as $entry) { // To use %SINCE%, you need Dunstan's 'Time Since' plugin. if(function_exists('time_since')) $data['SINCE']=time_since( time(), ec3_to_time($entry->start) ); // Month changed? $data['MONTH']=mysql2date($month_format,$entry->start); if((!$current_month || $current_month!=$data['MONTH']) && $template_month) { if($current_date) echo "</ul></li>\n"; if($current_month) echo "</ul></li>\n"; echo "<li class='ec3_list ec3_list_month'>" . ec3_format_str($template_month,$data)."\n<ul>\n"; $current_month=$data['MONTH']; $current_date=false; } // Date changed? $data['DATE'] =mysql2date($date_format, $entry->start); if((!$current_date || $current_date!=$data['DATE']) && $template_day) { if($current_date) echo "</ul></li>\n"; echo "<li class='ec3_list ec3_list_day'>" . ec3_format_str($template_day,$data)."\n<ul>\n"; $current_date=$data['DATE']; } if($entry->allday) $data['TIME']=__('all day','ec3'); else $data['TIME']=mysql2date($time_format,$entry->start); $data['TITLE'] = htmlentities( stripslashes(strip_tags($entry->post_title)), ENT_QUOTES,get_option('blog_charset') ); $data['LINK'] =get_permalink($entry->id); $data['WAAR'] =get_post_meta($entry->id, 'event_plaats', true); $data['ORGANISATIE'] =get_post_meta($entry->id, 'event_organisatie', true); $data['INSCHRIJVEN'] =get_post_meta($entry->id, 'event_inschrijven', true); $data['SOORT'] =get_post_meta($entry->id, 'event_soort', true); $data['AUTHOR']= htmlentities($entry->author,ENT_QUOTES,get_option('blog_charset')); echo " <tr>".ec3_format_str($template_event,$data)."</tr>\n"; } if($current_date) echo "</ul></li>\n"; if($current_month) echo "</ul></li>\n"; } else { echo "<tr>".__('No events.','ec3')."</tr>\n"; } echo "</table>\n"; }
And here’s how i call it from my template:
ec3_get_events2( '100', // limit '<td>%DATE%</td><td>%ORGANISATIE%</td><td><a href="%LINK%">%TITLE%</a></td><td>%WAAR%</td><td>%SOORT%</td><td>%INSCHRIJVEN%</td>', // template_event '' // template_day );
I hope it is usefull for others as well
- The topic ‘[plugin: Event Calendar 3] custom templating function’ is closed to new replies.