Hey guys! I'm displaying blog posts in two columns. I have two loops working really great with the rewind_posts(); function. The problem I'm having now is that I need to sort it with a couple of variables namely number of posts and category name. I'm not sure how to integrate those two variables into the dual loop I have. Here is my loop right now just displaying the most recent posts: <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) == 0) : $wp_query->next_post(); else : the_post(); ?> <div id="left-column"> <h3><?php the_title(); ?></h3> <?php the_excerpt(); ?> </div> <!-- end #left-column --> <?php endif; endwhile; else: ?> <div>Alternate content</div> <?php endif; ?> </div> <!-- end .column-werap-left --> <?php $i = 0; rewind_posts(); ?> <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $wp_query->next_post(); else : the_post(); ?> <div id="right-column"> <h3><?php the_title(); ?></h3> <?php the_excerpt(); ?> </div> <!-- end #right-column --> <?php endif; endwhile; else: ?> <div>Alternate content</div> <?php endif; ?> PHP: Does anyone know how I can get those two variables into the loop?
Thanks, Dodger. I do believe you're correct. The loop will be more flexible as WP_Query. My task now is trying to figure out how to incorporate the rewind_post as two WP_Querys.
the easiest way is open your archive/category page in your theme and see how the loop works there. just copy the loop and it just may work.
Maybe this will help... without rewind: // display posts organized by title in ascending order <?php $posts = query_posts( $query_string . '&orderby=title&order=asc' ); ?> <?php if( $posts ) : ?> <div class="post"> <h1>Ordered by Post Title (Ascending)</h1> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2> <p><?php the_content(); ?></p> <?php endforeach; ?> </div> <?php endif; ?> Code (markup): sourced from: http://perishablepress.com/press/2008/01/22/6-ways-to-customize-wordpress-post-order/