Query Posts with a taxonomy and group them by term

<?php
 $terms = get_terms("taxonomy");
 $count = count($terms);
 if ( $count > 0 ){
 foreach ( $terms as $term ) {
 ?>
 <div class="block">
 <h3 class="title"><?php echo $term->name; ?></h3>
 <div class="content">
 <?php
 $sticky=get_option('sticky_posts');
 $args = array(
 'taxonomy'=> $term->slug,
 'posts_per_page'=>-1,
 'post__not_in' => $sticky
 );
 query_posts($args);
 if (have_posts()) : while (have_posts()) : the_post(); ?>
 <div class="item">
 <h2 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
 <p><?php the_excerpt(); ?><a href="<?php the_permalink(); ?>">Keep reading</a></p>
 </div><!--item-->
 <?php
 endwhile;
 endif;
 ?>
 </div><!--cont-->
 </div><!--block-->
 <?php
 }
 }
?>

Revisions

Tags:

No comments yet.

Leave a Reply