How do I prevent one of two multiple loops from repeating on a second page?

I have a page with multiple loops, but the first loop repeats on the second (or Older) page. I want to keep the formatting but stop the post from repeating.

You can see the problem here: http://violentology.com/blog/

Read More

In my index.php file, I have the code:

<table width="980" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td colspan="3" style="background-color:#000">
            <?php get_the_image( array( 'meta_key' => 'feature_img', 'size' => 'full size', 'height' => '450', 'image_class' => 'post-feature-1' ) ); ?></td>
        </tr>
        <tr><td height="10"></td></tr>
        <tr>
    <td valign="top">
    <div id="main-col">
    <?php get_template_part( 'loop', 'index' ); ?>
    </div>
    </td>
    <td valign="top" id="mainsidebartd">
    <div id="linksidebar">
    <?php get_sidebar(); ?>
    </div>
    </td>
    <td width="10px">&nbsp;</td>
        </tr>
    </table>`

In my loop, the code is as follows:

<!-- First Loop -->
<div id="first_post">
<?php $my_query = new WP_Query('posts_per_page=1');
  while ($my_query->have_posts()) : $my_query->the_post();
  $do_not_duplicate = $post->ID;?>
        <!-- GETTING POST TITLE -->
        <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

        <!-- GETTING DATE AUTHOR AND COMMENTS -->
        <div class="date"><em><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></em> | <em><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></em>
        </div>
        <!-- GETTING ACTUAL POST -->
<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
        <?php the_excerpt(); ?>
<?php else : ?>
        <?php the_content(); ?>
<?php endif; ?>
  <?php endwhile; ?>
</div>

<!-- Second Loop -->
<?php /* Start the Loop. */ ?>
<?php if (have_posts()) : while ( have_posts() ) : the_post(); 
  if( $post->ID == $do_not_duplicate ) continue; ?>

<div id="singlepost">   <!-- POSITIONS INDIVIDUAL POSTS -->
<div class="post-box"><?php get_the_image( array( 'meta_key' => 'feature_img', 'size' => 'medium', 'height' => '200', 'image_class' => 'post-feature' ) ); ?></div>
        <!-- GETTING POST TITLE -->
            <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

        <!-- GETTING DATE AUTHOR AND COMMENTS -->
        <div class="date"><em><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></em> | <em><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></em>
        </div>
        <!-- GETTING ACTUAL POST -->
<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
        <?php the_excerpt(); ?>
<?php else : ?>
        <?php the_content('Continue Reading',FALSE,''); ?>
<?php endif; ?>
</div>

<?php endwhile; // End the loop. ?>

<?php endif; ?>

        <div id="postnav" class="postnav">
            <?php next_posts_link('&laquo; Older') ?> | <?php previous_posts_link('Newer &raquo;') ?>

    </div>`

Related posts

Leave a Reply

1 comment

  1. You can use this

    get_query_var('paged')
    

    to check to see if you are viewing the home page, page 1, page 2 and so on. so you could put this around the first block so it doesn’t show after the first page (which I think is what you want):

    if ( isset( get_query_var('paged') ) === false )
    {
      //do page 1 stuff here.
    }
    

    get_query_var() is just returning whether the “paged=?” bit appears in your URL, so it will return nothing for the home page. I’m not sure whether it returns null or “” for the home page, you’ll have to check.