• Hey all. I’m having a bit of trouble getting my loops to work the right way…basically what I’m trying to do is have two loops – one that will show the x number of recent posts as specified in the WP options panel, and another that will show the latest 15 posts from a specific category, in this case called products. I have followed the codex instructions and can’t seem to figure out what exactly is wrong and why the posts are still be duplicated. See my loop code below.

    <div class="news">
    
     <?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    
    			<!-- Post Stuff -->
    
    <?php endwhile; endif; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    		</div>
    
        </div>
    
    <div class="products">
    
      <?php $i = 0; // Create a new (incrementing) var ?>
      <?php $my_query = new WP_Query('category_name=products&showposts=15');
    
      while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; // check for product large image
    $pli = get_post_meta($post->ID, 'pli', $single = true); // check for item price
    $price = get_post_meta($post->ID, 'price', $single = true); ?>
    
      <?php $i++; // Increase count ?>
    
    <!-- Post Stuff -->
    
      <?php if ($i % 3 == 0): // if the result of the incrementing var is equal to zero ?>
      <div class="spacer"></div>
    <?php endif; ?>
      <?php endwhile; ?>
    </div>

    The incrementing var stuff is used to display posts the right way in a grid format. I removed additional display code from the above code sample.

    Any help would be greatly appreciated!
    Thanks in advance!!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter astereo

    (@astereo)

    Any ideas ?

    Thread Starter astereo

    (@astereo)

    Still haven’t been able to figure this out :S

    Thread Starter astereo

    (@astereo)

    bump

    Thread Starter astereo

    (@astereo)

    I hate to keep bumping this, but I’m developing a theme and this is the only thing that stands in the way of getting it completed.

    If you read the codex documentation you’ll find there’s a way to tell the WP loop not to repeat the post twice.

    Go here:
    http://codex.wordpress.org/The_Loop

    And scroll down to Multiple Loops in Action. You’ll see YOUR EXACT SCENARIO laid out for you in plain English and it took me less than five seconds to find it. Sorry you had to keep bumping this post. You should have been looking in the Codex instead of waiting for someone to hand you this information.

    If you ask me, you’ve got a lot more standing in the way than just your inabilty to solve your theme issue.

    Thread Starter astereo

    (@astereo)

    Maybe if you read my post you would see that I have looked in the codex. I have developed 7 WordPress themes in the past. My code is exactly how it should be as per the instructions in the codex and it is not working.

    Thread Starter astereo

    (@astereo)

    And to further test if do not duplicate worked or not, I replaced the loop with the exact one from the WordPress codex and posts were still being duplicated. (WP 2.5)

    If you ask me, you’ve got a lot more standing in the way than just your inabilty to solve your theme issue.

    Could you mean his ego?

    There are a few threads on this happening, if your code is the way it’s s’posed to be you might want to look through those threads.

    Zambrano Sergio

    (@sergiozambrano)

    Make sure you are not duplicating your index.php (or single.php or any other) in your server to test them.

    If you did, make sure you replace the pagename at the top of the code, or wp will read the first file it finds matching that name. wp doesn’t use filenames to find s page’s tamplate but that internal code.

    If that’s not the problem… I hope you fix it, since I’ve been helped with a script for a double loop which is doing the same to me (same content for both loops)

    http://wordpress.org/support/topic/251068?replies=3#post-1023595

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Multiple Loops, Do Not Duplicate Issues’ is closed to new replies.