display posts under their categories in two columns
-
I have created a Member Directory page and I am attempting to display a list of members under their category name, alphabetically in two columns (div.members-colA and div.members-colB). I am going to have about 70 members, which are actually posts listed (and more that will show up dynamically as they become members). The members should populate div.members-colA until the rounded post count reaches 1/2, at which time the posts should populate div.members-colB. I would like the category titles to be listed only once while the posts within that category are listed below them. So the category titles and their respective posts are populated within two divs that are 49% of their parent and floated left. The page on the development server shows posts that are definitely in the wrong category and a hap-hazard flow of content. Any help would be much appreciated!
<div class="members-colA"> <?php //get all categories then display all posts in each term $taxonomy = 'category'; $param_type = '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' => 'members', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1, 'orderby' => 'title', 'order' => 'ASC' ); $my_query = null; $my_query = new WP_Query($args); $i = 0; if( $my_query->have_posts() ) { ?> <h3 class="member-category"><?php echo $term->name; ?></h3> <?php if ($i == 0) while ($my_query->have_posts()) : $my_query->the_post(); echo '<div class="members-colC">'; ?> <p class="member-cat bold"><?php the_title(); ?></p> <?php the_content(); echo '</div>'; if ($i == (round($my_query->post_count / 2))) echo '</div><div class="members-colB">'; if ($i == round($my_query->post_count)) echo '</div>'; $i++; endwhile; } } } ?> <?php wp_reset_postdata(); ?> </div><!-- end .members-colB -->
- The topic ‘display posts under their categories in two columns’ is closed to new replies.