2013-05-13 76 views
0

我有多个循环,我想在我的WordPress博客上显示。该类别如下:WordPress多循环混淆

  • 顶故事(1每页)
  • 小故事(1每页)
  • 标准(1每页)
  • Quickfill(2每页)

我有4个循环来显示这些。我试图在每页上显示这些帖子数量,一旦显示出来,不要在另一个页面上再次显示,因为我不想显示重复内容。

我的循环如下。我似乎得到重复,当我试图让他们删除重复我倾向于删除一切,不知道如何。

头条新闻 - 第一环

<?php 
     global $do_not_duplicate; 
     $do_not_duplicate = array(); 

     $paged = max(1, get_query_var('paged')); 
     $my_query = new WP_Query('category_name=top-story&posts_per_page=1&paged='.$paged); 

     while ($my_query->have_posts()) : $my_query->the_post(); 
     $do_not_duplicate[] = $post->ID; ?> 
     // content 
<?php endwhile; ?> 

小故事 - 第二环

<?php 
     $my_query = new WP_Query('category_name=small-story&posts_per_page=1&paged='.$paged); 
     while ($my_query->have_posts()) : $my_query->the_post(); 
     if (in_array($post->ID, $do_not_duplicate)) continue; 
     $do_not_duplicate[] = $post->ID; 
     ?> 
     // content 
<?php endwhile; ?> 

普通职位(注:该类别居然被称为正常) - 第三环

<?php $my_query = new WP_Query('category_name=normal&posts_per_page=1&paged='.$paged); 
while ($my_query->have_posts()) : $my_query->the_post(); 
     if (in_array($post->ID, $do_not_duplicate)) continue; 
     $do_not_duplicate[] = $post->ID; ?> 
     // content 
<?php endwhile; ?> 

Quickfill - 第四个环

<?php 
     $int = 0; 
     $my_query = new WP_Query('category_name=quickfill&posts_per_page=2&paged='.$paged); 

     while ($my_query->have_posts()) : $my_query->the_post(); 
     if (in_array($post->ID, $do_not_duplicate)) continue;  
     $do_not_duplicate[] = $post->ID; 
      if ($int==0) { ?> 
       <hr class="seperator" /> 
       <div class="gr_bg_post"> 
        <img src="<?php bloginfo('template_directory'); ?>/images/quickfill.png" /> 
      <?php } ?> 
       <div class="fl"> 
        <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> 
        <?php the_content('<button type="button" class="read_more_green">Read More</button>'); ?> 
       </div> 
      <?php if ($int==1) { ?> 
      </div> 
     <?php } ?> 
     <?php $int++; ?> 
     <?php endwhile; ?> 

最后循环 - 显示帖子标准的WordPress协议...(我想这可能是与我的副本)

<?php 
     $my_query = new WP_Query(array('post_not_in' => $do_not_duplicate)); 
     if (have_posts()) : while ($my_query>have_posts()) : $my_query>the_post(); 
     ?> 
     // content 
<?php endwhile; endif; ?> 

我一直试图弄清楚这几天现在,我似乎无法停止重复显示,或得到正确的职位来显示。任何帮助是大大赞赏!

+0

尝试重置您的疑问,也许这个问题 - - http://codex.wordpress.org/Function_Reference/wp_reset_query – McNab 2013-05-13 08:43:57

+0

重置我的查询后仍然有同样的问题。 – PaulEx10 2013-05-13 17:38:52

回答

0

你缺少查询变量$my_query在最后一个查询

$my_query = new WP_Query(array('post_not_in' => $do_not_duplicate)); 

if ($my_query->have_posts()) : while ($my_query>have_posts()) : $my_query>the_post(); 
    // content 
endwhile; endif;