我有一个包含多个循环的页面,但第一个循环会在第二个(或更早的)页面上重复。我想保留格式,但阻止帖子重复。
您可以在此处看到问题:http://violentology.com/blog/
在我的索引中。php文件,我有代码:
<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"> </td>
</tr>
</table>`
在我的循环中,代码如下:
<!-- 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(\'« Older\') ?> | <?php previous_posts_link(\'Newer »\') ?>
</div>`