Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: Category Page
- *
- * A custom page template using custom field or Page Name = Category Name .
- *
- * The "Template Name:" bit above allows this to be selectable
- * from a dropdown menu on the edit page screen.
- */
- get_header(); ?>
- <div id="primary">
- <div id="content" role="main">
- <?php the_post(); ?>
- <?php get_template_part( 'content', 'page' ); ?>
- <?php
- /* Lets see if we have a category to display */
- global $post;
- // Save our page posts to use later
- $tmp_post = $post;
- $catid = "";
- // Do we have a category set on the custom fields
- $meta_cat = get_post_meta($post->ID, 'category', true);
- // Do we have an order set on the custom fields
- $asc = get_post_meta($post->ID, 'asc', true);
- // Do we want to display thumbnail and excerpts list?
- $excerpt = get_post_meta($post->ID, 'list', true);
- // Do not rely on what the admin entered
- $order = $asc ? 'ASC' : 'DESC';
- if( $meta_cat ) {
- // If we have a meta value is it numeric or a slug, return an id
- $catid = is_numeric( $meta_cat ) ? $meta_cat : get_cat_ID($meta_cat);
- }
- //Order by
- $ordered = get_post_meta($post->ID, 'orderby', true);
- $order_array=array('none','ID','author','title','date','modified','parent','rand','comment_count','menu_order');
- $orderby = in_array($ordered, $order_array) ? $order : 'ID';
- // No category ID so use the page slug to find a category
- if( !$catid ) $catid = get_cat_ID($post->post_name);
- // If we have a category id we can get the category posts
- if( $catid && is_numeric( $catid ) ) {
- $do_not_show_stickies = 1; // 0 to show stickies
- $args = array(
- 'cat' => $catid,
- 'paged' => $paged,
- 'orderby' => $orderby,
- 'order' => $order,
- 'ignore_sticky_posts' => $do_not_show_stickies
- );
- $wp_query= null;
- $wp_query = new WP_Query();
- $wp_query->query( $args );
- // Output our Query
- if ( $wp_query->have_posts() ) :
- twentyeleven_content_nav( 'nav-above' );
- while ( $wp_query->have_posts() ) :
- $wp_query->the_post();
- if( $excerpt ) :
- get_template_part( 'content', 'excerpt' );
- else :
- get_template_part( 'content', get_post_format() );
- endif;
- endwhile;
- twentyeleven_content_nav( 'nav-below');
- endif;
- }
- ?>
- <?php
- // Reset the post to the page post
- $post = $tmp_post;
- ?>
- <?php comments_template( '', true ); ?>
- </div><!-- #content -->
- </div><!-- #primary -->
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement