Tuesday, January 31, 2012

Category Posts

<?php
/*
Template Name: Category Posts
*/
get_header();
?>

        <div id="content-container">
            <div id="content" role="main">
<?php
//get all terms (e.g. categories or post tags), then display all posts in each term
$taxonomy = 'category';//  e.g. post_tag, category
$param_type = 'category__in'; //  e.g. tag__in, category__in
$term_args=array(
 'orderby' => 'name',
 'order' => 'ASC'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
 foreach( $terms as $term ) {
   $args=array(
     "$param_type" => array($term->term_id),
     'post_type' => 'post',
     'post_status' => 'publish',
     'posts_per_page' => -1,
     'caller_get_posts'=> 1
     );
   $my_query = null;
   $my_query = new WP_Query($args);
   if( $my_query->have_posts() ) {
     echo '<h2>List of Posts in '.$taxonomy .' '.$term->name.'</h2>';
     while ($my_query->have_posts()) : $my_query->the_post(); ?>
     <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <?php if ( is_front_page() ) { ?>
                        <h2 class="entry-title"><?php the_title(); ?></h2>
                    <?php } else { ?>
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                    <?php } ?>

                    <div class="entry-content">
                        <?php //the_content();
                        the_excerpt();
                        the_post_thumbnail(); ?>
                    </div><!-- .entry-content -->
                </div>
      
<?php

           endwhile;
   }
 }
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>

            </div><!-- #content -->
        </div><!-- #content-container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.