Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Template Name: SBW Home
- * Description: Displays Shows with video thumbs
- * Author: Marj Wyatt aka Virtually Marj
- Note: Must use as a page template and us wp_redirect() to refer to that page in order to work as home page.
- See this support thread for more info:
- https://wordpress.org/support/topic/multiple-queries-not-working-on-static-front-page?replies=5
- */
- add_filter( 'genesis_markup_site-inner_output', '__return_false' );
- add_filter( 'genesis_markup_content_output', '__return_false' );
- add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
- //* Remove the entry header markup (requires HTML5 theme support)
- remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
- remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
- // Execute custom home page. If no widgets active, then loop
- remove_action( 'genesis_before_header', 'vm_utility_bar' );
- add_action( 'genesis_meta', 'vm_custom_home_loop' );
- function vm_custom_home_loop() {
- //global $post;
- remove_action( 'genesis_loop', 'genesis_do_loop' );
- add_action( 'genesis_before_content', 'vm_home' );
- }
- // Home Top Gallery section
- function vm_home() {
- echo '<main class="content">';
- vm_home_do_top();
- vm_home_do_bottom();
- echo '</main>';
- }
- // Video gallery and widgets
- function vm_home_do_top() {
- echo '<section id="home-top"><div class="home-top clearfix">';
- echo '<div class="home-top-left two-thirds first">';
- if ( function_exists( 'soliloquy' ) ) { soliloquy( '54' );
- } else { if (is_active_sidebar( 'home-video' )) {
- genesis_widget_area( 'home-video', array(
- 'before' => '<aside class="home-video video-container">',
- 'after' => '</aside>',
- ) );
- }
- }
- /* Leave in just in case the widget is requested in the future */
- /*if ( is_active_sidebar( 'home-audio' ) ) {
- genesis_widget_area( 'home-audio', array(
- 'before' => '<aside class="home-audio">',
- 'after' => '</aside>',
- ) );
- }*/
- echo '</div><!--end home-top-left-->';
- echo '<div class = "home-top-right one-third">';
- if ( is_active_sidebar( 'home-right' ) ) {
- genesis_widget_area( 'home-right', array(
- 'before' => '<aside class="home-right">',
- 'after' => '</aside>',
- ) );
- }
- echo '</div><!--end home-top-right-->';
- echo '</div><!--end home-top --></section><!-- end home-top -->';
- }
- // Home posts section
- function vm_home_do_bottom() {
- echo '<section id="home-bottom"><div class="home-bottom clearfix">';
- echo '<aside class="home-bottom-left widget-area one-third first">';
- $args = array (
- 'post_type' => 'post',
- 'posts_per_page' => 10,
- );
- $vmQuery = new WP_Query ( $args );
- if ( $vmQuery->have_posts () ) :
- echo '<h4>Recent Posts: </h4>';
- echo '<ul class="home-posts-list">';
- while ( $vmQuery->have_posts() ) : $vmQuery->the_post();
- $postID_p = get_the_ID();
- $postDate_p = get_the_date('',$postID_p);
- $postType_p = get_post_type($postID_p);
- $postTitle_p = get_the_title($postID_p);
- $postLink_p = get_post_permalink($postID_p);
- echo '<li><a href="' . $postLink_p . '">' . $postTitle_p . '</a></li>';
- endwhile;
- endif;
- echo '</ul>';
- echo '</aside>';
- wp_reset_postdata();
- echo '<aside class="home-bottom-right widget-area two-thirds">';
- $n = 0;
- $args1 = array(
- 'post_type' => 'shows',
- 'posts_per_page' => 6,
- );
- $vmQuery1 = new WP_Query( $args1 );
- $showsCount = wp_count_posts( 'shows' )->publish;
- if ( $vmQuery1->have_posts() ) :
- echo '<h4>Recent Shows: ' . $showsCount . '</h4>';
- while ( $vmQuery1->have_posts() ) : $vmQuery1->the_post();
- $postID = get_the_ID();
- $postDate = get_the_date('', $postID);
- $postType = get_post_type( $postID );
- $postTitle = get_the_title($postID);
- $postLink = get_post_permalink( $postID );
- $columns = 2;
- if( 0 == $n || 0 == $n % $columns ) {
- echo '<div class="entry-content one-half first">';
- } else {
- echo '<div class="entry-content one-half">'; }
- if ( get_post_meta($postID, '_vm_showVideo', true) ) : // verify that custom data exists before output
- /* Build Video Thumb URL
- Ref links:
- http://stackoverflow.com/questions/9594943/regex-pattern-to-get-the-youtube-video-id-from-any-youtube-url
- https://developers.google.com/youtube/2.0/developers_guide_php?csw=1#Retrieving_Video_Entry
- http://php.net/manual/en/function.parse-url.php
- http://php.net/manual/en/function.extract.php
- http://php.net/manual/en/function.preg-replace.php
- */
- $postVideo = (get_post_meta($postID, '_vm_showVideo', true));
- $postVideoArray = (parse_url($postVideo));
- //turn $postVideoArray into variables
- extract($postVideoArray, EXTR_PREFIX_SAME, 'vid_');
- $postVideoQuery = $postVideoArray['query'];
- $postVideoHost = $postVideoArray['host'];
- $postVideoScheme = $postVideoArray['scheme'];
- //Extract video thumbnail from YouTube
- $postVidPattern = '/www/';
- $postVidReplace = 'img';
- $postVidImgHost = preg_replace($postVidPattern, $postVidReplace, $postVideoHost);
- $postVidIDPattern = '/v=/';
- $postVidIDReplace = '';
- $postVideoID = preg_replace($postVidIDPattern, $postVidIDReplace, $postVideoQuery);
- $postVideoThumb = $postVideoScheme . '://' . $postVidImgHost . '/vi/' . $postVideoID . '/0.jpg';
- echo '<h4><a href="' . $postLink . '">' . $postTitle . '</a></h4>';
- echo '<a class="ytThumbs" href="' . $postLink . '"><img class="ytThumb centered" src="' . $postVideoThumb . '" width="480" height="360" /></a>';
- endif;
- $n++;
- echo '</div>';
- endwhile;
- endif;
- wp_reset_postdata();
- echo '</aside>';
- echo '</div></section><!-- end home-bottom -->';
- }
- genesis();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement