The Events Calendar Shortcode - Version 1.2

Version Description

= 1.0.11 = Add Link to Thumbnail merge pull request from d4mation -Replaced extracted variables with $atts as using extract was deprecated =1.0.10 = Minor Error Change - fix name and slug = 1.0.9 = Minor Error Change - Multiple Categories = 1.0.8 = Add options : multi-categories - Thanks to sujin2f = 1.0.7 = Add options : contentorder, month, past, key - Thanks to sujin2f = 1.0.6 = Fix missing ul = 1.0.5 = * Add excerpt and thumbnail - Thanks to ankitpokhrel = 1.0.2 = * Add venue to shortcode - Thanks to ankitpokhrel = 1.0.1 = * Fix Firefox browser compatibility issue = 1 = * Initial Release

Download this release

Release Info

Developer brianhogg
Plugin Icon 128x128 The Events Calendar Shortcode
Version 1.2
Comparing to
See all releases

Version 1.2

Files changed (2) hide show
  1. readme.txt +133 -0
  2. the-events-calendar-shortcode.php +293 -0
readme.txt ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === The Events Calendar Shortcode ===
2
+ Contributors: brianhogg, dandelionweb, ankitpokhrel, sujin2f
3
+ Tags: event, events, calendar, shortcode, modern tribe
4
+ Requires at least: 4.0
5
+ Tested up to: 4.6
6
+ Stable tag: 1.2
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Adds shortcode functionality to The Events Calendar Plugin (Free Version) by Modern Tribe.
11
+
12
+ == Description ==
13
+
14
+ This plugin adds a shortcode for use with The Events Calendar Plugin (by Modern Tribe).
15
+
16
+ The shortcode displays lists of your events. You can control the event display with the shortcode options.
17
+ Example shortcode to show next 8 events in the category festival in ASC order with date showing [ecs-list-events cat='festival' limit='8']
18
+
19
+ = Shortcode Options: =
20
+ * Basic shortcode: [ecs-list-events]
21
+ * cat - Represents single event category. [ecs-list-events cat='festival']. Use commas when you want multiple categories [ecs-list-events cat='festival, workshops']
22
+ * limit - Total number of events to show. Default is 5. [ecs-list-events limit='3']
23
+ * order - Order of the events to be shown. Value can be 'ASC' or 'DESC'. Default is 'ASC'. Order is based on event date. [ecs-list-events order='DESC']
24
+ * date - To show or hide date. Value can be 'true' or 'false'. Default is true. [ecs-list-events eventdetails='false']
25
+ * venue - To show or hide the venue. Value can be 'true' or 'false'. Default is false. [ecs-list-events venue='true']
26
+ * excerpt - To show or hide the excerpt and set excerpt length. Default is false. [ecs-list-events excerpt='true'] //displays excerpt with length 100
27
+ excerpt='300' //displays excerpt with length 300
28
+ * thumb - To show or hide thumbnail image. Default is false. [ecs-list-events thumb='true'] //displays post thumbnail in default thumbnail dimension from media settings.
29
+ * You can use 2 other attributes: thumbwidth and thumbheight to customize the thumbnail size [ecs-list-events thumb='true' thumbwidth='150' thumbheight='150']
30
+ * message - Message to show when there are no events. Defaults to 'There are no upcoming events at this time.'
31
+ * viewall - Determines whether to show 'View all events' or not. Values can be 'true' or 'false'. Default to 'true' [ecs-list-events cat='festival' limit='3' order='DESC' viewall='false']
32
+ * contentorder - Manage the order of content with commas. Default to `title, thumbnail, excerpt, date, venue`. [ecs-list-events cat='festival' limit='3' order='DESC' viewall='false' contentorder='title, thumbnail, excerpt, date, venue']
33
+ * month - Show only specific Month. Type 'current' for displaying current month only [ecs-list-events cat='festival' month='2015-06']
34
+ * past - Show Outdated Events. [ecs-list-events cat='festival' past='yes']
35
+ * key - Order with Start Date [ecs-list-events cat='festival' key='start date']
36
+
37
+
38
+ Want to include your upcoming events in your newsletters?
39
+
40
+ >**[Check out Event Calendar Newsletter](https://eventcalendarnewsletter.com/?utm_source=wordpress.org&utm_medium=link&utm_campaign=event-cal-shortcode-readme&utm_content=tecs-description)**
41
+
42
+
43
+ == Installation ==
44
+
45
+ 1. Install The Events Calendar Shortcode Plugin from the WordPress.org repository or by uploading the-events-calendar-shortcode folder to the /wp-content/plugins directory. You must also install The Event Calendar Plugin by Modern Tribe and add your events to the calendar.
46
+
47
+ 2. Activate the plugin through the Plugins menu in WordPress
48
+
49
+
50
+ == Frequently Asked Questions ==
51
+
52
+ = What are the shortcode Options: =
53
+ = Shortcode Options: =
54
+ * Basic shortcode: [ecs-list-events]
55
+ * cat - Represents event category [ecs-list-events cat='festival'] or specify multiple categories [ecs-list-events cat='festival, workshops']
56
+ * limit - Total number of events to show. Default is 5. [ecs-list-events limit='3']
57
+ * order - Order of the events to be shown. Value can be 'ASC' or 'DESC'. Default is 'ASC'. Order is based on event date. [ecs-list-events order='DESC']
58
+ * date - To show or hide date. Value can be 'true' or 'false'. Default is true. [ecs-list-events eventdetails='false']
59
+ * venue - To show or hide the venue. Value can be 'true' or 'false'. Default is false. [ecs-list-events venue='true']
60
+ * excerpt - To show or hide the excerpt and set excerpt length. Default is false. [ecs-list-events excerpt='true'] //displays excerpt with length 100
61
+ excerpt='300' //displays excerpt with length 300
62
+ * thumb - To show or hide thumbnail image. Default is false. [ecs-list-events thumb='true'] //displays post thumbnail in default thumbnail dimension from media settings.
63
+ * You can use 2 other attributes: thumbwidth and thumbheight to customize the thumbnail size [ecs-list-events thumb='true' thumbwidth='150' thumbheight='150']
64
+ * message - Message to show when there are no events. Defaults to 'There are no upcoming events at this time.'
65
+ * viewall - Determines whether to show 'View all events' or not. Values can be 'true' or 'false'. Default to 'true' [ecs-list-events cat='festival' limit='3' order='DESC' viewall='false']
66
+ * contentorder - Manage the order of content with commas. Default to `title, thumbnail, excerpt, date, venue`. [ecs-list-events cat='festival' limit='3' order='DESC' viewall='false' contentorder='title, thumbnail, excerpt, date, venue']
67
+ * month - Show only specific Month. Type 'current' for displaying current month only. [ecs-list-events cat='festival' month='2015-06']
68
+ * past - Show Outdated Events. [ecs-list-events cat='festival' past='yes']
69
+ * key - Order with Start Date [ecs-list-events cat='festival' key='start date']
70
+
71
+ = How do I use this shortcode in a widget? =
72
+
73
+ * You can put the shortcode in a text widget.
74
+ * Not all themes support use of a shortcode in a widget. If a regular text widget doesn't work, put the shortcode in a <a href="https://wordpress.org/plugins/black-studio-tinymce-widget/">Visual Editor Widget</a>.
75
+
76
+ = What are the classes for styling the list of events? =
77
+ The plugin does not include styling. Events are listed in ul li tags with appropriate classes for styling.
78
+ * ul class="ecs-event-list"
79
+ * li class="ecs-event"
80
+ * event title link is H4 class="entry-title summary"
81
+ * date class is time
82
+ * venue class is venue
83
+ * span .ecs-all-events
84
+ * p .ecs-excerpt
85
+
86
+ = How do I include a list of events in a page template? =
87
+ include echo do_shortcode("[ecs-list-events]"); in the template where you want the events list to display.
88
+
89
+ == Upgrade Notice ==
90
+ = 1.0.11 =
91
+ Add Link to Thumbnail
92
+ merge pull request from d4mation -Replaced extracted variables with $atts as using extract was deprecated
93
+ =1.0.10 =
94
+ Minor Error Change - fix name and slug
95
+ = 1.0.9 =
96
+ Minor Error Change - Multiple Categories
97
+ = 1.0.8 =
98
+ Add options : multi-categories - Thanks to sujin2f
99
+ = 1.0.7 =
100
+ Add options : contentorder, month, past, key - Thanks to sujin2f
101
+ = 1.0.6 =
102
+ Fix missing ul
103
+ = 1.0.5 =
104
+ * Add excerpt and thumbnail - Thanks to ankitpokhrel
105
+ = 1.0.2 =
106
+ * Add venue to shortcode - Thanks to ankitpokhrel
107
+ = 1.0.1 =
108
+ * Fix Firefox browser compatibility issue
109
+ = 1 =
110
+ * Initial Release
111
+
112
+ == Changelog ==
113
+ = 1.0.11 =
114
+ Add Link to Thumbnail
115
+ merge pull request from d4mation -Replaced extracted variables with $atts as using extract was deprecated
116
+ = 1.0.10 =
117
+ Minor Error Change - fix name and slug
118
+ = 1.0.9 =
119
+ Minor Error Change - Multiple Categories
120
+ = 1.0.8 =
121
+ Add options : multi-categories - Thanks to sujin2f
122
+ = 1.0.7 =
123
+ * Add options : contentorder, month, past, key - Thanks to sujin2f
124
+ = 1.0.6 =
125
+ Fix missing ul
126
+ = 1.0.5 =
127
+ * Add excerpt and thumbnail - Thanks to ankitpokhrel
128
+ = 1.0.2 =
129
+ * Add venue to shortcode - Thanks to ankitpokhrel
130
+ = 1.0.1 =
131
+ * Fix Firefox browser compatibility issue
132
+ = 1 =
133
+ * Initial release
the-events-calendar-shortcode.php ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /***
3
+ Plugin Name: The Events Calendar Shortcode
4
+ Plugin URI: https://eventcalendarnewsletter.com/the-events-calendar-shortcode/
5
+ Description: An addon to add shortcode functionality for <a href="http://wordpress.org/plugins/the-events-calendar/">The Events Calendar Plugin (Free Version) by Modern Tribe</a>.
6
+ Version: 1.2
7
+ Author: Event Calendar Newsletter (Brian Hogg)
8
+ Author URI: https://eventcalendarnewsletter.com/the-events-calendar-shortcode/
9
+ Contributors: Brainchild Media Group, Reddit user miahelf, tallavic, hejeva2
10
+ Contributor URL: http://brainchildmediagroup.com, http://www.reddit.com/user/miahelf
11
+ License: GPL2 or later
12
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
+ */
14
+
15
+ // Avoid direct calls to this file
16
+ if ( !defined( 'ABSPATH' ) ) {
17
+ header( 'Status: 403 Forbidden' );
18
+ header( 'HTTP/1.1 403 Forbidden' );
19
+ exit();
20
+ }
21
+
22
+ /**
23
+ * Events calendar shortcode addon main class
24
+ *
25
+ * @package events-calendar-shortcode
26
+ * @author Dandelion Web Design Inc.
27
+ * @version 1.0.10
28
+ */
29
+ class Events_Calendar_Shortcode
30
+ {
31
+ /**
32
+ * Current version of the plugin.
33
+ *
34
+ * @since 1.0.0
35
+ */
36
+ const VERSION = '1.0.11';
37
+
38
+ /**
39
+ * Constructor. Hooks all interactions to initialize the class.
40
+ *
41
+ * @since 1.0.0
42
+ * @access public
43
+ *
44
+ * @see add_shortcode()
45
+ */
46
+ public function __construct()
47
+ {
48
+ add_shortcode('ecs-list-events', array($this, 'ecs_fetch_events') ); // link new function to shortcode name
49
+ } // END __construct()
50
+
51
+ /**
52
+ * Fetch and return required events.
53
+ * @param array $atts shortcode attributes
54
+ * @return string shortcode output
55
+ */
56
+ public function ecs_fetch_events( $atts )
57
+ {
58
+ /**
59
+ * Check if events calendar plugin method exists
60
+ */
61
+ if ( !function_exists( 'tribe_get_events' ) ) {
62
+ return;
63
+ }
64
+
65
+ global $wp_query, $post;
66
+ $output = '';
67
+
68
+ $atts = shortcode_atts( array(
69
+ 'cat' => '',
70
+ 'month' => '',
71
+ 'limit' => 5,
72
+ 'eventdetails' => 'true',
73
+ 'time' => null,
74
+ 'past' => null,
75
+ 'venue' => 'false',
76
+ 'author' => null,
77
+ 'message' => 'There are no upcoming events at this time.',
78
+ 'key' => 'End Date',
79
+ 'order' => 'ASC',
80
+ 'viewall' => 'false',
81
+ 'excerpt' => 'false',
82
+ 'thumb' => 'false',
83
+ 'thumbwidth' => '',
84
+ 'thumbheight' => '',
85
+ 'contentorder' => 'title, thumbnail, excerpt, date, venue',
86
+ 'event_tax' => '',
87
+ ), $atts, 'ecs-list-events' );
88
+
89
+ // Category
90
+ if ( $atts['cat'] ) {
91
+ if ( strpos( $atts['cat'], "," ) !== false ) {
92
+ $atts['cats'] = explode( ",", $atts['cat'] );
93
+ $atts['cats'] = array_map( 'trim', $atts['cats'] );
94
+ } else {
95
+ $atts['cats'] = $atts['cat'];
96
+ }
97
+
98
+ $atts['event_tax'] = array(
99
+ 'relation' => 'OR',
100
+ array(
101
+ 'taxonomy' => 'tribe_events_cat',
102
+ 'field' => 'name',
103
+ 'terms' => $atts['cats'],
104
+ ),
105
+ array(
106
+ 'taxonomy' => 'tribe_events_cat',
107
+ 'field' => 'slug',
108
+ 'terms' => $atts['cats'],
109
+ )
110
+ );
111
+ }
112
+
113
+ // Past Event
114
+ $meta_date_compare = '>=';
115
+ $meta_date_date = date( 'Y-m-d' );
116
+
117
+ if ( $atts['time'] == 'past' || !empty( $atts['past'] ) ) {
118
+ $meta_date_compare = '<';
119
+ }
120
+
121
+ // Key
122
+ if ( str_replace( ' ', '', trim( strtolower( $atts['key'] ) ) ) == 'startdate' ) {
123
+ $atts['key'] = '_EventStartDate';
124
+ } else {
125
+ $atts['key'] = '_EventEndDate';
126
+ }
127
+ // Date
128
+ $atts['meta_date'] = array(
129
+ array(
130
+ 'key' => $atts['key'],
131
+ 'value' => $meta_date_date,
132
+ 'compare' => $meta_date_compare,
133
+ 'type' => 'DATETIME'
134
+ )
135
+ );
136
+
137
+ // Specific Month
138
+ if ( $atts['month'] == 'current' ) {
139
+ $atts['month'] = date( 'Y-m' );
140
+ }
141
+ if ($atts['month']) {
142
+ $month_array = explode("-", $atts['month']);
143
+
144
+ $month_yearstr = $month_array[0];
145
+ $month_monthstr = $month_array[1];
146
+ $month_startdate = date( "Y-m-d", strtotime( $month_yearstr . "-" . $month_monthstr . "-01" ) );
147
+ $month_enddate = date( "Y-m-01", strtotime( "+1 month", strtotime( $month_startdate ) ) );
148
+
149
+ $atts['meta_date'] = array(
150
+ array(
151
+ 'key' => $atts['key'],
152
+ 'value' => array($month_startdate, $month_enddate),
153
+ 'compare' => 'BETWEEN',
154
+ 'type' => 'DATETIME'
155
+ )
156
+ );
157
+ }
158
+
159
+ $posts = get_posts( array(
160
+ 'post_type' => 'tribe_events',
161
+ 'posts_per_page' => $atts['limit'],
162
+ 'tax_query'=> $atts['event_tax'],
163
+ 'meta_key' => $atts['key'],
164
+ 'orderby' => 'meta_value',
165
+ 'author' => $atts['author'],
166
+ 'order' => $atts['order'],
167
+ 'meta_query' => array( $atts['meta_date'] )
168
+ ) );
169
+
170
+ if ($posts) {
171
+ $output .= '<ul class="ecs-event-list">';
172
+ $atts['contentorder'] = explode( ',', $atts['contentorder'] );
173
+
174
+ foreach( $posts as $post ) :
175
+ setup_postdata( $post );
176
+
177
+ $output .= '<li class="ecs-event">';
178
+
179
+ // Put Values into $output
180
+ foreach ( $atts['contentorder'] as $contentorder ) {
181
+ switch ( trim( $contentorder ) ) {
182
+ case 'title' :
183
+ $output .= '<h4 class="entry-title summary">' .
184
+ '<a href="' . tribe_get_event_link() . '" rel="bookmark">' . apply_filters( 'ecs_event_list_title', get_the_title(), $atts ) . '</a>
185
+ </h4>';
186
+ break;
187
+
188
+ case 'thumbnail' :
189
+ if( self::isValid($atts['thumb']) ) {
190
+ $thumbWidth = is_numeric($atts['thumbwidth']) ? $atts['thumbwidth'] : '';
191
+ $thumbHeight = is_numeric($atts['thumbheight']) ? $atts['thumbheight'] : '';
192
+ if( !empty($thumbWidth) && !empty($thumbHeight) ) {
193
+ $output .= get_the_post_thumbnail(get_the_ID(), array($thumbWidth, $thumbHeight) );
194
+ } else {
195
+
196
+ $size = ( !empty($thumbWidth) && !empty($thumbHeight) ) ? array( $thumbWidth, $thumbHeight ) : 'medium';
197
+
198
+ if ( $thumb = get_the_post_thumbnail( get_the_ID(), $size ) ) {
199
+ $output .= '<a href="' . tribe_get_event_link() . '">';
200
+ $output .= $thumb;
201
+ $output .= '</a>';
202
+ }
203
+ }
204
+ }
205
+ break;
206
+
207
+ case 'excerpt' :
208
+ if( self::isValid($atts['excerpt']) ) {
209
+ $excerptLength = is_numeric($atts['excerpt']) ? $atts['excerpt'] : 100;
210
+ $output .= '<p class="ecs-excerpt">' .
211
+ self::get_excerpt($excerptLength) .
212
+ '</p>';
213
+ }
214
+ break;
215
+
216
+ case 'date' :
217
+ if( self::isValid($atts['eventdetails']) ) {
218
+ $output .= '<span class="duration time">' . apply_filters( 'ecs_event_list_details', tribe_events_event_schedule_details(), $atts ) . '</span>';
219
+ }
220
+ break;
221
+
222
+ case 'venue' :
223
+ if( self::isValid($atts['venue']) ) {
224
+ $output .= '<span class="duration venue"><em> at </em>' . apply_filters( 'ecs_event_list_venue', tribe_get_venue(), $atts ) . '</span>';
225
+ }
226
+ break;
227
+ }
228
+ }
229
+ $output .= '</li>';
230
+ endforeach;
231
+ $output .= '</ul>';
232
+
233
+ if( self::isValid($atts['viewall']) ) {
234
+ $output .= '<span class="ecs-all-events"><a href="' . apply_filters( 'ecs_event_list_viewall_link', tribe_get_events_link(), $atts ) .'" rel="bookmark">' . translate( 'View All Events', 'tribe-events-calendar' ) . '</a></span>';
235
+ }
236
+
237
+ } else { //No Events were Found
238
+ $output .= translate( $atts['message'], 'tribe-events-calendar' );
239
+ } // endif
240
+
241
+ wp_reset_query();
242
+
243
+ return $output;
244
+ }
245
+
246
+ /**
247
+ * Checks if the plugin attribute is valid
248
+ *
249
+ * @since 1.0.5
250
+ *
251
+ * @param string $prop
252
+ * @return boolean
253
+ */
254
+ private function isValid( $prop )
255
+ {
256
+ return ($prop !== 'false');
257
+ }
258
+
259
+ /**
260
+ * Fetch and trims the excerpt to specified length
261
+ *
262
+ * @param integer $limit Characters to show
263
+ * @param string $source content or excerpt
264
+ *
265
+ * @return string
266
+ */
267
+ private function get_excerpt( $limit, $source = null )
268
+ {
269
+ $excerpt = get_the_excerpt();
270
+ if( $source == "content" ) {
271
+ $excerpt = get_the_content();
272
+ }
273
+
274
+ $excerpt = preg_replace(" (\[.*?\])", '', $excerpt);
275
+ $excerpt = strip_tags( strip_shortcodes($excerpt) );
276
+ $excerpt = substr($excerpt, 0, $limit);
277
+ $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
278
+ $excerpt .= '...';
279
+
280
+ return $excerpt;
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Instantiate the main class
286
+ *
287
+ * @since 1.0.0
288
+ * @access public
289
+ *
290
+ * @var object $events_calendar_shortcode holds the instantiated class {@uses Events_Calendar_Shortcode}
291
+ */
292
+ global $events_calendar_shortcode;
293
+ $events_calendar_shortcode = new Events_Calendar_Shortcode();