Snippets
Created by
Joseph Dickson
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | <?php
/*
* for global variables, since it is being changed or updated from time to time,
* please refer to Related Resources for more information
* https://codex.wordpress.org/WPMU_Functions/restore_current_blog
*/
global $switched;
switch_to_blog(1); // Switch to another blog by ID#
// Check if The Events Calendar plugin is active
// $events = tribe_get_events(); assigns array to $events variable
if(function_exists('tribe_get_events')) {
// Get all events from starting -1 hour before the present date and time to 90 days into the future
$events = tribe_get_events( array(
'start_date' => date( 'Y-m-d H:i:s', strtotime( '-1 hour' ) ),
'end_date' => date( 'Y-m-d H:i:s', strtotime( '+90 day' ) ),
'order' => 'ASC',
/*
* Exclude events by tax_query -- https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
* This requires the tribe events category slug for Pitzer Now otherwise the event will not display
*/
'tax_query'=> array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'pitzer-now',
)
),
));
// Get all events from starting -360 days before the present date and and ending an hour ago
$past = tribe_get_events( array(
'start_date' => date( 'Y-m-d H:i:s', strtotime( '-360 day' ) ),
'end_date' => date( 'Y-m-d H:i:s', strtotime( '-1 hour' ) ),
'order' => 'DESC',
/*
* Exclude events by tax_query -- https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
* This requires the tribe events category slug for Pitzer Now otherwise the event will not display
*/
'tax_query'=> array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'pitzer-now',
)
),
));
// Display message if calendar is active but there are no events
if ( empty( $events ) ) {
echo '<strong class="events">No Upcoming Events Available</strong>';
} else {
echo '<div class="calendar upcoming">';
echo '<strong class="events">Upcoming Events</strong>';
// Create Foundation block grid https://get.foundation/sites/docs/flex-grid.html#block-grids
echo '<div class="row small-up-1 medium-up-3 large-up-5">';
} foreach( $events as $event ) {
// start .column
echo '<div class="column">';
// get link and echo it
echo '<a href="' . tribe_get_event_link( $event ) . '">';
// get and echo the title
echo '<h1 class="event-title">' . get_the_title( $event ) . '</h1>';
// get and echo calendar icon, weekday, month, date
echo '<p class="event-details"><span class="dashicons dashicons-calendar-alt"></span> ' . tribe_get_start_date( $event, true, 'l, F j') . '<br />';
// get and echo clock icon, start time
echo '<span class="dashicons dashicons-clock"></span> ' . tribe_get_start_date( $event, true, 'g:i a') . '<br />';
// if event has a location get the location and echo it alogn with the icon
if (tribe_get_venue( $event ) ) {
echo '<span class="dashicons dashicons-location-alt"></span> ' . tribe_get_venue( $event );
}
// close paragraph started above
echo '</p>';
// close link echoed above
echo '</a>';
// close .column
echo '</div>';
}
// close .calendar
echo '</div>';
echo '</div>';
} else {
// Events calendar plugin not active
echo '<strong class="events">The Events Calendar plugin is not active</strong>';
}
if(function_exists('tribe_get_events')) {
// Display message if calendar is active but there are no events
if ( empty( $past ) ) {
// No Past Events on the calendar
// loop through each event on the calendar
} else {
echo '<div class="calendar past">';
echo '<strong class="events">Past Events</strong>';
// Create Foundation block grid https://get.foundation/sites/docs/flex-grid.html#block-grids
echo '<div class="row small-up-1 medium-up-3 large-up-5" >';
} foreach( $past as $event ) {
// start .column
echo '<div class="column">';
// get link and echo it
echo '<a href="' . tribe_get_event_link( $event ) . '">';
// get and echo the title
echo '<h1 class="event-title">' . get_the_title( $event ) . '</h1>';
// get and echo calendar icon, weekday, month, date
echo '<p class="event-details"><span class="dashicons dashicons-calendar-alt"></span> ' . tribe_get_start_date( $event, true, 'l, F j, Y') . '<br />';
// get and echo clock icon, start time
echo '<span class="dashicons dashicons-clock"></span> ' . tribe_get_start_date( $event, true, 'g:i a') . '<br />';
// if event has a location get the location and echo it alogn with the icon
if (tribe_get_venue( $event ) ) {
echo '<span class="dashicons dashicons-location-alt"></span> ' . tribe_get_venue( $event );
}
// close paragraph started above
echo '</p>';
// close link echoed above
echo '</a>';
// close .column
echo '</div>';
}
// close .calendar
echo '</div>';
echo '</div>';
} else {
// Events calendar plugin not active
}
restore_current_blog(); // Switch back to current blog
|
Comments (2)
You can clone a snippet to your computer for local editing. Learn more.
Offering this freely for study and re-use. Consider it licensed under GPL3