Wordpress Loop help needed

Discussion in 'WordPress' started by jami0821, Jan 17, 2011.

  1. #1
    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?
     
    jami0821, Jan 17, 2011 IP
  2. Dodger

    Dodger Peon

    Messages:
    1,494
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would try separate WP_Query loops. See the WP Query page in the codex for more information.
     
    Dodger, Jan 17, 2011 IP
  3. jami0821

    jami0821 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    jami0821, Jan 18, 2011 IP
  4. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #4
    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.
     
    olddocks, Jan 18, 2011 IP
  5. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #5
    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/
     
    adbox, Jan 19, 2011 IP
  6. Dodger

    Dodger Peon

    Messages:
    1,494
    Likes Received:
    60
    Best Answers:
    0
    Trophy Points:
    0
    #6
    He wants two lists, but I think if he remove post_rewind altogether it might work.
     
    Dodger, Jan 19, 2011 IP