Advertisement
Digitalraindrops

page-category.php

Oct 7th, 2011
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: Category Page
  4.  *
  5.  * A custom page template using custom field or Page Name = Category Name .
  6.  *
  7.  * The "Template Name:" bit above allows this to be selectable
  8.  * from a dropdown menu on the edit page screen.
  9.  */
  10. get_header(); ?>
  11.  
  12.         <div id="primary">
  13.             <div id="content" role="main">
  14.                
  15.                 <?php the_post(); ?>
  16.  
  17.                 <?php get_template_part( 'content', 'page' ); ?>
  18.                
  19.                 <?php
  20.                     /* Lets see if we have a category to display */
  21.                     global $post;
  22.                    
  23.                     // Save our page posts to use later
  24.                     $tmp_post = $post;
  25.                     $catid = "";
  26.                    
  27.                     // Do we have a category set on the custom fields
  28.                     $meta_cat = get_post_meta($post->ID, 'category', true);
  29.                    
  30.                     // Do we have an order set on the custom fields
  31.                     $asc = get_post_meta($post->ID, 'asc', true);
  32.                    
  33.                     // Do we want to display thumbnail and excerpts list?
  34.                     $excerpt = get_post_meta($post->ID, 'list', true);
  35.                    
  36.                     // Do not rely on what the admin entered
  37.                     $order = $asc ? 'ASC' : 'DESC';
  38.                     if( $meta_cat ) {
  39.                         // If we have a meta value is it numeric or a slug, return an id
  40.                         $catid = is_numeric( $meta_cat ) ? $meta_cat : get_cat_ID($meta_cat);
  41.                     }
  42.                    
  43.                     //Order by
  44.                     $ordered = get_post_meta($post->ID, 'orderby', true);
  45.                     $order_array=array('none','ID','author','title','date','modified','parent','rand','comment_count','menu_order');
  46.                     $orderby = in_array($ordered, $order_array) ? $order : 'ID';
  47.                    
  48.                     // No category ID so use the page slug to find a category
  49.                     if( !$catid ) $catid = get_cat_ID($post->post_name);  
  50.                    
  51.                     // If we have a category id we can get the category posts
  52.                     if( $catid  && is_numeric( $catid ) ) {
  53.                         $do_not_show_stickies = 1; // 0 to show stickies
  54.                         $args = array(
  55.                             'cat' => $catid,
  56.                             'paged' => $paged,
  57.                             'orderby' => $orderby,
  58.                             'order' => $order,
  59.                             'ignore_sticky_posts' => $do_not_show_stickies
  60.                         );
  61.                        
  62.                         $wp_query= null;
  63.                         $wp_query = new WP_Query();
  64.                         $wp_query->query( $args );
  65.                            
  66.                         // Output our Query
  67.                         if ( $wp_query->have_posts() ) :
  68.                        
  69.                             twentyeleven_content_nav( 'nav-above' );
  70.                            
  71.                             while ( $wp_query->have_posts() ) :
  72.                                
  73.                                 $wp_query->the_post();
  74.                                 if( $excerpt ) :
  75.                                     get_template_part( 'content', 'excerpt' );
  76.                                 else :
  77.                                     get_template_part( 'content', get_post_format() );
  78.                                 endif;
  79.                             endwhile;
  80.                            
  81.                             twentyeleven_content_nav( 'nav-below');
  82.                         endif; 
  83.                     }  
  84.                 ?>
  85.                
  86.                 <?php
  87.                     // Reset the post to the page post
  88.                     $post = $tmp_post;
  89.                 ?>
  90.                
  91.                 <?php comments_template( '', true ); ?>
  92.  
  93.             </div><!-- #content -->
  94.         </div><!-- #primary -->
  95.  
  96. <?php get_footer(); ?>
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement