Advertisement
bdbrown

Static Front Page and Blog Home Page Layouts

Apr 17th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.94 KB | None | 0 0
  1. WP Theme: Hueman
  2. Display the static Front page using the Standard Blog List layout, and the blog Home page using the default post list layout
  3.  
  4. *******************************************************************************************************************
  5.  
  6. <!-- front-page.php
  7. This is a copy of index.php with the following changes:
  8.  1. the main loop is replaced with a custom query
  9.  2. added a query reset after the loop is processed
  10. -->
  11.  
  12. <?php get_header(); ?>
  13.  
  14. <section class="content">
  15.  
  16.     <?php get_template_part('inc/page-title'); ?>
  17.  
  18.     <div class="pad group">
  19.        
  20.         <?php get_template_part('inc/featured'); ?>
  21.  
  22.  
  23.         <!-- if there are featured posts and they aren't included in the post previews -->
  24.         <?php if ( ot_get_option('featured-posts-count') != '0' && ( !ot_get_option('featured-posts-include') ) ): ?>
  25.             <?php $featured_post_ids = get_featured_post_ids(); ?>
  26.             <?php $args = array( 'post_type'=>'post', 'post__not_in'=>$featured_post_ids ); ?>
  27.         <?php else: ?>
  28.             <?php $args = array( 'post_type'=>'post' ); ?>
  29.         <?php endif; ?>
  30.         <?php $frontpage_posts = new WP_query($args); ?>
  31.  
  32.  
  33.         <?php if ( $frontpage_posts->have_posts() ) : ?>
  34.        
  35.             <?php if ( ot_get_option('blog-standard') == 'on' ): ?>
  36.                 <?php while ( $frontpage_posts->have_posts() ): $frontpage_posts->the_post(); ?>
  37.                     <?php get_template_part('content-standard'); ?>
  38.                 <?php endwhile; ?>
  39.             <?php else: ?>
  40.                 <div class="post-list group">
  41.                 <?php $i = 1; echo '<div class="post-row">'; while ( $frontpage_posts->have_posts() ): $frontpage_posts->the_post(); ?>
  42.                     <?php get_template_part('content'); ?>
  43.                 <?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?>
  44.                 </div><!--/.post-list-->
  45.             <?php endif; ?>
  46.  
  47.             <?php get_template_part('inc/pagination'); ?>
  48.            
  49.             <?php wp_reset_postdata(); ?>
  50.        
  51.         <?php endif; ?>
  52.        
  53.     </div><!--/.pad-->
  54.    
  55. </section><!--/.content-->
  56.  
  57. <?php get_sidebar(); ?>
  58.  
  59. <?php get_footer(); ?>
  60. <!-- End of front-page.php -->
  61.  
  62. *******************************************************************************************************************
  63.  
  64. <!-- home.php
  65. This is a copy of index.php with the following changes:
  66.  1. the featured posts slider has been removed
  67.  2. the check for blog-standard has been reversed so the page display is the opposite of front-page.php
  68. -->
  69.  
  70. <?php get_header(); ?>
  71.  
  72. <section class="content">
  73.  
  74.     <?php get_template_part('inc/page-title'); ?>
  75.    
  76.     <div class="pad group">
  77.                
  78.     <?php if ( have_posts() ) : ?>
  79.        
  80.             <!-- reverse the criteria so it displays the Standard Post List when the option is OFF -->
  81.             <?php if ( ot_get_option('blog-standard') != 'on' ): ?>
  82.                 <?php while ( have_posts() ): the_post(); ?>
  83.                     <?php get_template_part('content-standard'); ?>
  84.                 <?php endwhile; ?>
  85.             <?php else: ?>
  86.                 <div class="post-list group">
  87.                 <?php $i = 1; echo '<div class="post-row">'; while ( have_posts() ): the_post(); ?>
  88.                     <?php get_template_part('content'); ?>
  89.                 <?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?>
  90.                 </div><!--/.post-list-->
  91.             <?php endif; ?>
  92.        
  93.             <?php get_template_part('inc/pagination'); ?>
  94.            
  95.         <?php endif; ?>
  96.        
  97.     </div><!--/.pad-->
  98.    
  99. </section><!--/.content-->
  100.  
  101. <?php get_sidebar(); ?>
  102.  
  103. <?php get_footer(); ?>
  104. <!-- End of home.php -->
  105.  
  106. *******************************************************************************************************************
  107.  
  108. In /inc/featured.php change TWO lines
  109.  
  110. from this:
  111. <?php if ( is_home() && !is_paged() && ( ot_get_option('featured-posts-count')
  112.  
  113. to this:
  114. <?php if ( is_front_page() && !is_paged() && ( ot_get_option('featured-posts-count')
  115.  
  116. *******************************************************************************************************************
  117.  
  118. In /inc/page-title.php, at the top of the file
  119.  
  120. change this:
  121.     <?php if ( is_home() ) : ?>
  122.         <h2><?php echo alx_blog_title(); ?></h2>
  123.        
  124. to this:
  125.     <!-- add check for_static Front Page -->
  126.     <?php if ( is_home() || is_front_page() ) : ?>
  127.         <h2><?php echo alx_blog_title(); ?></h2>
  128.  
  129. *******************************************************************************************************************
  130.  
  131. Add these two functions, including the // comment lines, to your child theme functions.php file
  132.  
  133.  
  134. // Since the Blog page doesn't have Featured Posts we need to include all
  135. // posts on that page. Override default theme pre_get_posts function.
  136. function alx_pre_get_posts( $query ) {}
  137.  
  138.  
  139. // copy of alx_get_featured_post_ids but it needs to be local
  140. function get_featured_post_ids() {
  141.     $args = array(
  142.         'category'  => ot_get_option('featured-category'),
  143.         'numberposts'   => ot_get_option('featured-posts-count')
  144.     );
  145.     $posts = get_posts($args);
  146.     if ( !$posts ) return false;
  147.     foreach ( $posts as $post )
  148.         $ids[] = $post->ID;
  149.     return $ids;
  150. }
  151.  
  152. *******************************************************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement