Advertisement
alchymyth

'catalog' page template 2011

Dec 20th, 2012
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: 'Catalog'
  4.  *
  5.  * a page template to display sub category posts of the 'catalog' category in a three column layout
  6.  *
  7.  * @package WordPress
  8.  * @subpackage Twenty_Eleven
  9.  * @since Twenty Eleven 1.0
  10.  */
  11.  
  12. get_header(); ?>
  13.  
  14.         <section id="primary">
  15.             <div id="content" role="main">
  16.  
  17.             <?php $category = get_term_by('slug', 'catalog', 'category');
  18.             $cat_query = new WP_Query( array(
  19.                 'cat' => $category->term_id ));
  20.             if( $cat_query->have_posts() ) : ?>
  21.  
  22.                 <header class="page-header">
  23.                     <h1 class="page-title"><?php
  24.                         printf( __( 'Category Archives: %s', 'twentyeleven' ), '<span>' . $category->name . '</span>' );
  25.                     ?></h1>
  26.  
  27.                     <?php
  28.                         $category_description = category_description( $category->term_id );
  29.                         if ( ! empty( $category_description ) )
  30.                             echo apply_filters( 'category_archive_meta', '<div class="category-archive-meta">' . $category_description . '</div>' );
  31.                     ?>
  32.                 </header>
  33.  
  34.  
  35.     <?php $sub_cats = get_categories( 'parent=' .  $category->term_id ); // get direct sub categories http://codex.wordpress.org/Function_Reference/get_categories //
  36.    
  37.     if( $sub_cats ) foreach( $sub_cats as $sub_cat ) :
  38.    
  39.     $sub_cat_query = new WP_Query( array(
  40.         'posts_per_page' => -1,
  41.         'category__in' => array( $sub_cat->term_id )
  42.         ));
  43.     if( $sub_cat_query->have_posts() ) : ?>
  44.     <h3 class="cat-title">Sub-category <?php echo $sub_cat->name; ?> for category <?php echo single_cat_title(); ?></h3>
  45.    
  46.     <div class="columns">
  47.     <?php while( $sub_cat_query->have_posts() ) : $sub_cat_query->the_post(); ?>
  48.    
  49.     <div class="column column<?php echo $sub_cat_query->current_post%3; ?>">     <div class="post" id="post-<?php echo $post->ID; ?>">
  50.     POST WITH THUMBNAIL AND TITLE; YOU KNOW WHAT TO PUT HERE
  51.     </div></div><!--/ .column and .post -->
  52.     <?php endwhile; ?> 
  53.    
  54.     </div><!--/ .columns -->
  55.     <div class="clear"></div> <!--clear any floats-->
  56.     <?php endif; wp_reset_postdata();
  57.    
  58.     endforeach; // ends foreach( $sub_cats as $sub_cat ) //        
  59.     ?>
  60.  
  61.  
  62.             <?php else : ?>
  63.  
  64.                 <article id="post-0" class="post no-results not-found">
  65.                     <header class="entry-header">
  66.                         <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
  67.                     </header><!-- .entry-header -->
  68.  
  69.                     <div class="entry-content">
  70.                         <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
  71.                         <?php get_search_form(); ?>
  72.                     </div><!-- .entry-content -->
  73.                 </article><!-- #post-0 -->
  74.  
  75.             <?php endif; wp_reset_postdata(); ?>
  76.  
  77.             </div><!-- #content -->
  78.         </section><!-- #primary -->
  79.  
  80. <?php get_sidebar(); ?>
  81. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement