Advertisement
marjwyatt

Genesis Home Page with Posts and CPTs

Dec 26th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.12 KB | None | 0 0
  1. <?php
  2. /*  Template Name: SBW Home
  3. * Description: Displays Shows with video thumbs
  4. * Author: Marj Wyatt aka Virtually Marj
  5.  
  6. Note: Must use as a page template and us wp_redirect() to refer to that page in order to work as home page.
  7. See this support thread for more info:
  8. https://wordpress.org/support/topic/multiple-queries-not-working-on-static-front-page?replies=5
  9. */
  10.  
  11. add_filter( 'genesis_markup_site-inner_output', '__return_false' );
  12. add_filter( 'genesis_markup_content_output', '__return_false' );
  13. add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
  14.  
  15. //* Remove the entry header markup (requires HTML5 theme support)
  16. remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
  17. remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
  18.  
  19. // Execute custom home page. If no widgets active, then loop
  20.     remove_action( 'genesis_before_header', 'vm_utility_bar' );
  21.     add_action( 'genesis_meta', 'vm_custom_home_loop' );
  22.  
  23. function vm_custom_home_loop() {
  24.     //global $post;
  25.     remove_action( 'genesis_loop', 'genesis_do_loop' );
  26.     add_action( 'genesis_before_content', 'vm_home' );
  27. }
  28.  
  29. // Home Top Gallery section
  30.  
  31. function vm_home() {
  32.     echo '<main class="content">';
  33.         vm_home_do_top();
  34.         vm_home_do_bottom();
  35.     echo '</main>';
  36. }
  37.  
  38. // Video gallery and widgets
  39. function vm_home_do_top() {
  40.     echo '<section id="home-top"><div class="home-top clearfix">';
  41.     echo '<div class="home-top-left two-thirds first">';
  42.     if ( function_exists( 'soliloquy' ) ) { soliloquy( '54' );
  43.     } else { if (is_active_sidebar( 'home-video' )) {
  44.             genesis_widget_area( 'home-video', array(
  45.                 'before' => '<aside class="home-video video-container">',
  46.                 'after' => '</aside>',
  47.             ) );
  48.       }
  49.       }
  50.         /* Leave in just in case the widget is requested in the future */
  51.         /*if ( is_active_sidebar( 'home-audio' ) ) {
  52.             genesis_widget_area( 'home-audio', array(
  53.                 'before' => '<aside class="home-audio">',
  54.                 'after' => '</aside>',
  55.             ) );
  56.         }*/
  57.     echo '</div><!--end home-top-left-->';
  58.     echo '<div class = "home-top-right one-third">';
  59.     if ( is_active_sidebar( 'home-right' ) ) {
  60.         genesis_widget_area( 'home-right', array(
  61.             'before' => '<aside class="home-right">',
  62.             'after' => '</aside>',
  63.         ) );
  64.     }
  65.     echo '</div><!--end home-top-right-->';
  66.     echo '</div><!--end home-top --></section><!-- end home-top -->';
  67. }
  68.  
  69. // Home posts section
  70.  
  71. function vm_home_do_bottom() {
  72.     echo '<section id="home-bottom"><div class="home-bottom clearfix">';
  73.         echo '<aside class="home-bottom-left widget-area one-third first">';
  74.         $args = array (
  75.             'post_type' => 'post',
  76.             'posts_per_page' => 10,
  77.             );
  78.         $vmQuery = new WP_Query ( $args );
  79.         if ( $vmQuery->have_posts () ) :
  80.             echo '<h4>Recent Posts: </h4>';
  81.             echo '<ul class="home-posts-list">';
  82.         while ( $vmQuery->have_posts() ) : $vmQuery->the_post();
  83.             $postID_p = get_the_ID();
  84.             $postDate_p = get_the_date('',$postID_p);
  85.             $postType_p = get_post_type($postID_p);
  86.             $postTitle_p = get_the_title($postID_p);
  87.             $postLink_p = get_post_permalink($postID_p);
  88.  
  89.             echo '<li><a href="' . $postLink_p . '">' . $postTitle_p . '</a></li>';
  90.  
  91.         endwhile;
  92.         endif;
  93.         echo '</ul>';
  94.         echo '</aside>';
  95.         wp_reset_postdata();
  96.         echo '<aside class="home-bottom-right widget-area two-thirds">';
  97.         $n = 0;
  98.         $args1 = array(
  99.             'post_type' => 'shows',
  100.             'posts_per_page' => 6,
  101.             );
  102.         $vmQuery1 = new WP_Query( $args1 );
  103.         $showsCount = wp_count_posts( 'shows' )->publish;
  104.         if ( $vmQuery1->have_posts() ) :
  105.             echo '<h4>Recent Shows: ' . $showsCount . '</h4>';
  106.         while ( $vmQuery1->have_posts() ) : $vmQuery1->the_post();
  107.             $postID = get_the_ID();
  108.             $postDate = get_the_date('', $postID);
  109.             $postType = get_post_type( $postID );
  110.             $postTitle = get_the_title($postID);
  111.             $postLink = get_post_permalink( $postID );
  112.             $columns = 2;
  113.             if( 0 == $n || 0 == $n % $columns ) {
  114.                 echo '<div class="entry-content one-half first">';
  115.             } else {
  116.                 echo '<div class="entry-content one-half">'; }
  117.                 if ( get_post_meta($postID, '_vm_showVideo', true) ) : // verify that custom data exists before output
  118.                     /* Build Video Thumb URL
  119.                     Ref links:
  120.                     http://stackoverflow.com/questions/9594943/regex-pattern-to-get-the-youtube-video-id-from-any-youtube-url
  121.                     https://developers.google.com/youtube/2.0/developers_guide_php?csw=1#Retrieving_Video_Entry
  122.                     http://php.net/manual/en/function.parse-url.php
  123.                     http://php.net/manual/en/function.extract.php
  124.                     http://php.net/manual/en/function.preg-replace.php
  125.                     */
  126.                     $postVideo = (get_post_meta($postID, '_vm_showVideo', true));
  127.                     $postVideoArray = (parse_url($postVideo));
  128.                     //turn $postVideoArray into variables
  129.                     extract($postVideoArray, EXTR_PREFIX_SAME, 'vid_');
  130.                     $postVideoQuery = $postVideoArray['query'];
  131.                     $postVideoHost = $postVideoArray['host'];
  132.                     $postVideoScheme = $postVideoArray['scheme'];
  133.                     //Extract video thumbnail from YouTube
  134.                     $postVidPattern = '/www/';
  135.                     $postVidReplace = 'img';
  136.                     $postVidImgHost = preg_replace($postVidPattern, $postVidReplace, $postVideoHost);
  137.                     $postVidIDPattern = '/v=/';
  138.                     $postVidIDReplace = '';
  139.                     $postVideoID = preg_replace($postVidIDPattern, $postVidIDReplace, $postVideoQuery);
  140.                     $postVideoThumb = $postVideoScheme . '://' . $postVidImgHost . '/vi/' . $postVideoID . '/0.jpg';
  141.                     echo '<h4><a href="' . $postLink . '">' . $postTitle . '</a></h4>';
  142.                     echo '<a class="ytThumbs" href="' . $postLink . '"><img class="ytThumb centered" src="' . $postVideoThumb . '" width="480" height="360" /></a>';
  143.                     endif;
  144.                     $n++;
  145.                 echo '</div>';
  146.             endwhile;
  147.             endif;
  148.             wp_reset_postdata();
  149.         echo '</aside>';
  150.     echo '</div></section><!-- end home-bottom -->';
  151. }
  152.  
  153. genesis();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement