Advertisement
duck__boy1981

page.php and loop.php

May 15th, 2013
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.95 KB | None | 0 0
  1. <?php
  2. /**
  3.  * page.php
  4.  * @package WordPress
  5.  * @subpackage DyneDrewett
  6.  */
  7.  
  8. $page_atts = get_page_atts();
  9. $post_atts = get_post_atts($page_atts);
  10.  
  11. get_header();
  12. ?>
  13.     <div id="content-container">
  14.  
  15.         <div class="content-left">
  16.            
  17.             <!-- Page loop -->
  18.             <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
  19.            
  20.                     <h1><?php the_title(); ?></h1>
  21.                    
  22.                     <div>
  23.                         <?php the_content(); ?>                
  24.                     </div>
  25.                    
  26.                 <?php endwhile; ?>
  27.                
  28.             <?php endif; ?>
  29.            
  30.             <?php if($page_atts['include_separator']) : ?>
  31.                 <div class="separator solid"></div>
  32.             <?php endif; ?>
  33.            
  34.             <!-- Post loop -->
  35.             <?php if($page_atts['show_post_loop']) : ?>
  36.            
  37.                 <?php query_posts($post_atts); ?>
  38.                 <?php get_template_part('loop', 'index'); ?>
  39.                 <?php wp_reset_query(); ?>
  40.                
  41.             <?php endif; ?>
  42.        
  43.         </div>
  44.        
  45.         <?php get_sidebar(); ?>
  46.        
  47.     </div>
  48.    
  49. <?php get_footer(); ?>
  50.  
  51. <?php
  52.  
  53. function get_page_atts(){
  54.    
  55.     global $post;
  56.    
  57.     $post_id = $post->ID;
  58.    
  59.     switch($post_id) :
  60.        
  61.         /** Partnerships and Careers */
  62.         case 716 : // Partnerships
  63.         case 162 : // Careers
  64.             $atts['include_separator'] = true;
  65.             $atts['show_post_loop'] = true;
  66.             break;
  67.            
  68.         default :
  69.             $atts['include_separator'] = false;
  70.             $atts['show_post_loop'] = false;
  71.        
  72.     endswitch;
  73.    
  74.     return $atts;
  75.    
  76. }
  77.  
  78. function get_post_atts($page_atts){
  79.    
  80.     global $post;
  81.    
  82.     /** Check to see if we actully need to get the Post attributes */
  83.     if(!$page_atts['show_post_loop']) :
  84.         return false;
  85.     endif;
  86.    
  87.     $post_id = $post->ID;
  88.    
  89.     $atts = array(
  90.         'orderby' => 'date',
  91.         'order' => ASC,
  92.         'paged' => get_query_var('paged'),
  93.         'posts_per_page' => 5,
  94.         'post_status' => 'publish',
  95.         'post_type' => POST_TYPE_NEWS
  96.     );
  97.    
  98.     switch($post_id) :
  99.        
  100.         /** Partnerships */
  101.         case 716 :
  102.             $atts['orderby'] = 'name';
  103.             $atts['post_type'] = POST_TYPE_PARTNERSHIP;
  104.             break;     
  105.            
  106.         /** Careers */
  107.         case 162 :
  108.             $atts['orderby'] = 'name';
  109.             $atts['post_type'] = POST_TYPE_CAREERXXX;
  110.             break;     
  111.        
  112.     endswitch;
  113.    
  114.     return $atts;
  115.    
  116. }
  117. ?>
  118.  
  119. <?php
  120. /**
  121.  * loop.php
  122.  * @package WordPress
  123.  * @subpackage DyneDrewett
  124.  */
  125. ?>
  126.  
  127. <?php $post_count = 1; ?>
  128.  
  129. <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
  130.  
  131.         <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  132.            
  133.             <!-- Post image -->
  134.             <?php if(get_post_image()) : ?>
  135.            
  136.                 <div class="post_image">
  137.                     <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute('before=View post - '); ?>" class="linked_img">
  138.                         <?php post_image(); ?>
  139.                     </a>
  140.                 </div>
  141.            
  142.             <?php endif; ?>
  143.            
  144.             <div class="post_text">
  145.            
  146.                 <!-- Post Title -->
  147.                 <div class="post_title">
  148.                     <h2 class="alt-link"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute('before=View post - '); ?>">
  149.                         <?php the_title(); ?>
  150.                     </a></h2>
  151.                 </div>
  152.                
  153.                 <!-- Post excerpt -->
  154.                 <div class="post_content">
  155.                     <?php the_excerpt(); ?>        
  156.                 </div>
  157.                
  158.             </div>
  159.            
  160.             <div class="clear"></div>
  161.            
  162.         </div>
  163.        
  164.         <?php article_seperator($post_count) ?>
  165.         <?php $post_count++; ?>
  166.    
  167.     <?php endwhile; ?>
  168.    
  169.     <?php if(function_exists('show_page_numbers')) : show_page_numbers(); endif; ?>
  170.    
  171. <?php else : ?>
  172.  
  173.     <?php if(is_page(162)) : // Careers ?>
  174.        
  175.         <div class="no-posts-found">
  176.        
  177.             <!-- Post content -->
  178.             <div class="post_content">
  179.                 <p>Sorry, Dyne Drewett are not currently recruiting.</p>
  180.                 <p>Please check back regularly to be the first to know about any oppurtunities.</p>
  181.             </div>
  182.            
  183.         </div>
  184.        
  185.     <?php elseif(is_search()) : ?>
  186.    
  187.         <div class="no-posts-found">
  188.        
  189.             <!-- Post Title -->
  190.             <div class="post_title">
  191.                 <h2>No results found</h2>
  192.             </div>
  193.            
  194.             <!-- Post content -->
  195.             <div class="post_content">
  196.                 <p>Sorry, we couldn't find any matching posts.</p>
  197.                 <p>Please try changing your search parameters and try again.</p>
  198.             </div>
  199.            
  200.         </div>
  201.        
  202.     <?php endif; ?>
  203.            
  204. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement