<?php
/**
* Template Name: 'Catalog'
*
* a page template to display sub category posts of the 'catalog' category in a three column layout
*
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/
get_header(); ?>
<section id="primary">
<div id="content" role="main">
<?php $category = get_term_by('slug', 'catalog', 'category');
$cat_query = new WP_Query( array(
'cat' => $category->term_id ));
if( $cat_query->have_posts() ) : ?>
<header class="page-header">
<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'twentyeleven' ), '<span>' . $category->name . '</span>' );
?></h1>
<?php
$category_description = category_description( $category->term_id );
if ( ! empty( $category_description ) )
echo apply_filters( 'category_archive_meta', '<div class="category-archive-meta">' . $category_description . '</div>' );
?>
</header>
<?php $sub_cats = get_categories( 'parent=' . $category->term_id ); // get direct sub categories http://codex.wordpress.org/Function_Reference/get_categories //
if( $sub_cats ) foreach( $sub_cats as $sub_cat ) :
$sub_cat_query = new WP_Query( array(
'posts_per_page' => -1,
'category__in' => array( $sub_cat->term_id )
));
if( $sub_cat_query->have_posts() ) : ?>
<h3 class="cat-title">Sub-category <?php echo $sub_cat->name; ?> for category <?php echo single_cat_title(); ?></h3>
<div class="columns">
<?php while( $sub_cat_query->have_posts() ) : $sub_cat_query->the_post(); ?>
<div class="column column<?php echo $sub_cat_query->current_post%3; ?>"> <div class="post" id="post-<?php echo $post->ID; ?>">
POST WITH THUMBNAIL AND TITLE; YOU KNOW WHAT TO PUT HERE
</div></div><!--/ .column and .post -->
<?php endwhile; ?>
</div><!--/ .columns -->
<div class="clear"></div> <!--clear any floats-->
<?php endif; wp_reset_postdata();
endforeach; // ends foreach( $sub_cats as $sub_cat ) //
?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; wp_reset_postdata(); ?>
</div><!-- #content -->
</section><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>