Advertisement
Digitalraindrops

page-category.php

Sep 4th, 2011
1,337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.48 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.                     // No category ID so use the page slug to find a category
  44.                     if( !$catid ) $catid = get_cat_ID($post->post_name);  
  45.                    
  46.                     // If we have a category id we can get the category posts
  47.                     if( $catid  && is_numeric( $catid ) ) {
  48.                         $do_not_show_stickies = 1; // 0 to show stickies
  49.                         $args = array(
  50.                             'cat' => $catid,
  51.                             'paged' => $paged,
  52.                             'order' => $order,
  53.                             'ignore_sticky_posts' => $do_not_show_stickies
  54.                         );
  55.                        
  56.                         $wp_query= null;
  57.                         $wp_query = new WP_Query();
  58.                         $wp_query->query( $args );
  59.                            
  60.                         // Output our Query
  61.                         if ( $wp_query->have_posts() ) :
  62.                        
  63.                             twentyeleven_content_nav( 'nav-above' );
  64.                            
  65.                             while ( $wp_query->have_posts() ) :
  66.                                
  67.                                 $wp_query->the_post();
  68.                                 if( $excerpt ) :
  69.                                     get_template_part( 'content', 'excerpt' );
  70.                                 else :
  71.                                     get_template_part( 'content', get_post_format() );
  72.                                 endif;
  73.                             endwhile;
  74.                            
  75.                             twentyeleven_content_nav( 'nav-below');
  76.                         endif; 
  77.                     }  
  78.                 ?>
  79.                
  80.                 <?php
  81.                     // Reset the post to the page post
  82.                     $post = $tmp_post;
  83.                 ?>
  84.                
  85.                 <?php comments_template( '', true ); ?>
  86.  
  87.             </div><!-- #content -->
  88.         </div><!-- #primary -->
  89.  
  90. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement