wordpress loop – ¿Cómo evito que uno de los dos bucles múltiples se repita en una segunda página?

Pregunta:

Tengo una página con múltiples bucles, pero el primer bucle se repite en la segunda página (o más antigua). Quiero mantener el formato pero evitar que la publicación se repita.

Puedes ver el problema aquí: http://violentology.com/blog/

En mi archivo index.php, tengo el código:

<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>`

En mi ciclo, el código es el siguiente:

<!-- 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' ) ); ?>"><?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' ) ); ?>"><?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>`

Respuesta:

Puedes usar esto

get_query_var('paged')

para comprobar si está viendo la página de inicio, la página 1, la página 2, etc. para que puedas poner esto alrededor del primer bloque para que no se muestre después de la primera página (que creo que es lo que quieres):

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

get_query_var () solo devuelve si el "paged =?" bit aparece en su URL, por lo que no devolverá nada para la página de inicio. No estoy seguro de si devuelve nulo o "" para la página de inicio, tendrá que comprobarlo.

Leave a Comment

Your email address will not be published. Required fields are marked *

web tasarım