Last active
August 4, 2017 15:28
-
-
Save mdailey77/11355eda85ec4ea79afe296f4fcebaff to your computer and use it in GitHub Desktop.
Display featured and upcoming webinars on the same page by calling the corresponding method. For use with the Events Calendar WordPress plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class getWebinars { | |
function get_featured_webinars(){ | |
// Ensure the global $post variable is in scope | |
global $post; | |
$featuredwebinars = tribe_get_events( | |
array( | |
'eventDisplay' => 'upcoming', | |
'posts_per_page' => 2, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'tribe_events_cat', | |
'field' => 'slug', | |
'terms' => 'webinar', | |
) | |
), | |
'meta_query' => array( | |
array( | |
'key' => '_tribe_featured', | |
'compare' => 'EXISTS', | |
) | |
) | |
) | |
); | |
if ($featuredwebinars) : | |
$count = count($featuredwebinars); | |
if ($count == 1): | |
foreach($featuredwebinars as $post): | |
setup_postdata($post); | |
echo '<div class="featured-item item-center">'; | |
echo '<div class="event-image"><img src="' . tribe_event_featured_image($post, 'full', false, false) . '" /></div>'; | |
echo '<div class="event-title"><a href="' . get_permalink($post) . '">' . $post->post_title . '</a></div>'; | |
echo '<div class="item-excerpt">' . the_excerpt() . '</div>'; | |
echo '<div class="event-date">' . tribe_get_start_date($post) . '</div>'; | |
echo '<div class="watch-button"><a href="' . $post->guid .'" target="_blank">Register Now</a></div>'; | |
echo '</div>'; | |
endforeach; | |
elseif ($count == 0): | |
echo '<p>No featured webinars found.</p>'; | |
else: | |
foreach($featuredwebinars as $post): | |
setup_postdata($post); | |
echo '<div class="featured-item">'; | |
echo '<div class="event-image"><img src="' . tribe_event_featured_image($post, 'full', false, false) . '" /></div>'; | |
echo '<div class="event-title"><a href="' . get_permalink($post) . '">' . $post->post_title . '</a></div>'; | |
echo '<div class="item-excerpt">' . the_excerpt() . '</div>'; | |
echo '<div class="event-date">' . tribe_get_start_date($post) . '</div>'; | |
echo '<div class="watch-button"><a href="' . $post->guid .'" target="_blank">Register Now</a></div>'; | |
echo '</div>'; | |
endforeach; | |
endif; | |
else: | |
echo '<p>No featured webinars found.</p>'; | |
endif; | |
wp_reset_postdata(); | |
} | |
function get_upcoming_webinars($upcomingnum){ | |
// Ensure the global $post variable is in scope | |
global $post; | |
$categoryslug = 'webinar'; | |
// check if page is a webinar category page | |
if ( is_tax('tribe_events_cat') ) { | |
$categoryslug = get_query_var( 'tribe_events_cat' ); | |
} | |
$upcomingwebinars = tribe_get_events( | |
array( | |
'eventDisplay' => 'upcoming', | |
'posts_per_page' => $upcomingnum, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'tribe_events_cat', | |
'field' => 'slug', | |
'terms' => $categoryslug, | |
), | |
), | |
) | |
); | |
if ($upcomingwebinars) : | |
foreach($upcomingwebinars as $post): | |
setup_postdata($post); | |
$webinarthumbnail = get_post_meta( $post->ID, '_ecp_custom_4', true ); | |
echo '<div class="webinar-item">'; | |
if ( $webinarthumbnail ) : | |
echo '<div class="webinar-item-image">'; | |
echo '<img src="' . $webinarthumbnail . '" />'; | |
echo '</div>'; | |
endif; | |
echo '<div class="webinar-item-content">'; | |
echo '<div class="item-title"><a href="' . get_permalink($post) . '">' . $post->post_title . '</a></div>'; | |
echo '<div class="item-excerpt">' . the_excerpt() . '</div>'; | |
echo '</div>'; | |
echo '<a class="watch-button-mobile" href="' . get_permalink($post) . '">REGISTER NOW</a>'; | |
echo '</div>'; | |
endforeach; | |
else: | |
echo '<p>No upcoming webinars found.</p>'; | |
endif; | |
wp_reset_postdata(); | |
} | |
function get_ondemand_webinars($ondemandnum){ | |
// Ensure the global $post variable is in scope | |
global $post; | |
$categoryslug = 'webinar'; | |
if (!$ondemandnum) { | |
$ondemandnum = 4; | |
} | |
if ( is_tax('tribe_events_cat') ) { | |
$categoryslug = get_query_var( 'tribe_events_cat' ); | |
} | |
$ondemand = tribe_get_events( | |
array( | |
'posts_per_page' => $ondemandnum, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'tribe_events_cat', | |
'field' => 'slug', | |
'terms' => $categoryslug, | |
) | |
), | |
'meta_query' => array( | |
array( | |
'key' => '_tribe_ondemand', | |
'value' => 'yes', | |
'compare' => '=', | |
) | |
) | |
) | |
); | |
if ( $ondemand): | |
foreach($ondemand as $post): | |
setup_postdata($post); | |
$ondemandurl = get_post_meta( $post->ID, '_tribe_ondemandurl', true ); | |
$webinarthumbnail = get_post_meta( $post->ID, '_ecp_custom_4', true ); | |
echo '<div class="webinar-item">'; | |
if ( $webinarthumbnail ) : | |
echo '<div class="webinar-item-image">'; | |
echo '<img src="' . $webinarthumbnail . '" />'; | |
echo '</div>'; | |
endif; | |
echo '<div class="webinar-item-content">'; | |
echo '<div class="item-title"><a href="' . $ondemandurl . '">' . $post->post_title . '</a></div>'; | |
echo '<div class="item-excerpt">' . the_excerpt() . '</div>'; | |
echo '</div>'; | |
echo '<div class"webinar-uberflip">'; | |
echo '<a class="watch-button-mobile" href="' . $ondemandurl . '">WATCH NOW</a>'; | |
echo '</div>'; | |
echo '</div>'; | |
endforeach; | |
wp_reset_postdata(); | |
else: | |
echo '<p>No on-demand webinars found.</p>'; | |
endif; | |
} | |
} | |
// end of getWebinars class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment