Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

<?php
// 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) {
                 $args=array(
                '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>
                        </div>

                      </li>

        <?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;">
                            <p>
                              <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 } ?>
                              </span>    
                            </p>                                          
                          </div>
                          <?php $post_counter++; ?>
                        </li>

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

                  } // END foreach $tax_terms
                } // END if $tax_terms
                ?>
share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
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. –  Studioleland Aug 3 '11 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. –  Tristar Web Design Aug 5 '11 at 13:48
    
So I guess I will edit my post to make the nested loop much more clear. Please review. –  Studioleland Aug 9 '11 at 22:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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