Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php //in a category archive, show one post per sub category, no duplicates, in three columns
- //alchymyth 2011
- $cat = get_query_var('cat');
- $no_duplicates = array();
- $sub_cats = get_categories('parent='.$cat); //get the direct sub categories
- if( $sub_cats ) :
- foreach( $sub_cats as $sub_cat ) :
- /*get the latest post of this subcat;
- for instance: output the category name, the post title, and the excerpt of one post*/
- $args = array(
- 'posts_per_page' =>1,
- 'category__in' => array($sub_cat->term_id),
- 'post__not_in' => $no_duplicates
- );
- $cat_query = new WP_Query( $args );
- if( $cat_query->have_posts() ) : while( $cat_query->have_posts() ) :
- $cat_query->the_post();
- $no_duplicates[] = $post->ID; ?>
- <?php $column = ($column == '') ? 'columnleft' : (($column == 'columnleft') ? 'columnmiddle' : (($column == 'columnmiddle') ? 'columnright' : 'columnleft' )); // define the css class for the respective column ?>
- <div class="<?php echo $column; ?>">
- <h3>
- <a href="<?php echo get_category_link($sub_cat->term_id); ?>" title="View all posts filed under <?php echo $sub_cat->name; ?>"><?php echo $sub_cat->name; ?></a>
- </h3>
- <a href="<?php the_permalink(); ?>" rel="bookmark" title=" <?php the_title_attribute(); ?>" class="title"><?php the_title(); ?></a>
- <?php the_excerpt(); ?>
- </div>
- <!-- END <?php echo $column; ?> COLUMN -->
- <?php endwhile; endif; ?>
- <?php endforeach; //ends: foreach( $sub_cats as $sub_cat )
- endif; //ends: if( $sub_cats ) ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement