• 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 -->
Viewing 3 replies - 1 through 3 (of 3 total)
  • It seems to me you could calculate half of your post count (rounded) before your have_posts loop and set to a value. Print the left column head. Run a counter loop until you get to that value printing titles/content, fall out of that loop, format the next column and print the column head, then run another loop from counter to post-count to print the rest of the content.

    Sort of block and tackle, but should work.

    Thread Starter seifs4

    (@seifs4)

    Sorry for my ineptitude, but how would I run a counter loop until I get to the value set to the half (rounded) post count? It’s got me stumped.

    After you execute:
    $my_query = new WP_Query($args);
    Then your new $my_query object exposes post_count method.

    $counter=(round($my_query->post_count/2));

    It might be me who is totally missing something, these things can go like that

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘display posts under their categories in two columns’ is closed to new replies.