Here is what I need to do with 5 columns on the "archive" page:

I can already loop through the categories and posts in a loop to display them quite nicely, I just cant figure out how to split it into columns. I also need it to be paged. Basically show only 18 post titles/excerpts per page. Any help? My loop below:

UPDATE: I am posted the working solution below. This works perfectly to break a continuous loop of posts sorted and displayed by category of any type or taxonomy.

WHAT STILL NEEDS WORK: I cannot seem to figure out how to make the paging work. I need the paging to count total posts (ignoring the categories) and display only 12 or so per page. I have added the paging code but it is commented out.

// for a given post type, return all
        $post_type = 'retailers';
        $tax = 'states';
        $tax_terms = get_terms($tax);
        $post_counter = 0; // reset so we can generate columns 
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

            if ($tax_terms) { ?>

            <ul class="column_wrap" style="margin:0 10px; padding:0; width:165px; float:left;">

            <?php foreach ($tax_terms as $tax_term) {
                'post_type' => $post_type,
                "$tax" => $tax_term->slug,
                'post_status' => 'publish',
                'posts_per_page' => -1,
              //'posts_per_page' => 15,
              //'paged' => $paged,
                'orderby' => 'title',
                'order' => 'ASC',
                'caller_get_posts'=> 1
                ); // END $args

                $my_query = null; // clear the query variable
                $my_query = new WP_Query($args);

                if( $my_query->have_posts() ) { ?>

                      <li class="column_row" style="float:left;">

                        <div class="retailer_state_wrap" style="width:165px; float:left;">
                            <h4><?php echo $tax_term->name; ?></h4>


        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
                      <li class="column_row" style="float:left;">

                          <div class="retailer_wrap retailer_id-<?php the_ID(); ?>" style="padding:0; width:165px; float:left;">
                              <span class="retailer_title"><?php the_title(); ?></span><br />
                              <span class="retailer_address">
                                <?php if (get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0', true)) { ?>
                                  <?php echo get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_2_numInSet_0', true); ?>
                                <?php } ?>
                                <?php echo " "; ?>
                                <?php if (get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0', true)) { ?>
                                  <?php echo get_post_meta($post->ID, '_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0', true); ?>
                                <?php } ?>
                              </span><br />
                              <span class="retailer_phone">                               
                                <?php if (get_post_meta($post->ID, '_simple_fields_fieldGroupID_2_fieldID_3_numInSet_0', true)) {
                                  echo get_post_meta($post->ID, '_simple_fields_fieldGroupID_2_fieldID_3_numInSet_0', true); ?>
                                <?php } ?>
                          <?php $post_counter++; ?>

                        <?php if ( 0 == $post_counter % 7 ) { ?>
                          <ul class="column_wrap" style="margin:0 10px; padding:0; width:165px; float:left;">
                        <?php } ?>
                      //wp_pagenavi( array( 'query' => $my_query ) ); 
                    } // END if have_posts loop

                  } // END foreach $tax_terms
                } // END if $tax_terms

1 Answer 1


What you will need to do is loop through an array of category IDs. For example:

$categories = get_categories();

Then loop through the categories, and use the category id in your query_posts:

foreach($categories as $category) {
    $args = array(
    'cat' = $category->ID
    // return your loop here...

Or something... assuming I understand your question.

  • Well I can already display 1 long list of categories with posts using my query. I just need to know how to divide that long list into 5 columns and then make it paged. Here is the manual HTML version bottlesup-07112011.31two.com/bottlesup-retailers to give you an idea. Commented Aug 3, 2011 at 15:36
  • OK, that wasn't too clear in your question. Have a look at the offset parameter for query_posts. Or, show say 25 posts per page, and add closing and opening div after every 5 to split it. Commented Aug 5, 2011 at 13:48
  • So I guess I will edit my post to make the nested loop much more clear. Please review. Commented Aug 9, 2011 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.