2012-03-05 15 views
0

私は2つの列を使用して私のポストを表示しようとすると、互いにフィットすることを確認するために、私は2つの垂直列を作成しようとし、左側がオッド、右側がオッドである。そして、wp_pagenavi()を使ってナビゲーション作業をしたり、他のページがうまく動作したり、私が意図しているように投稿を表示したりしますが、最後のページでは1回の投稿が2回繰り返されます。Wordpressのポストは、最後のページで2回繰り返す

ここで私は考えてループ部分

<?php if (have_posts()) : ?> 

      <?php /* Start the Loop */ ?> 
     <div id="holder" class="left"> 

      <?php while (have_posts()) : ?> 
      <?php 
       $postcount++; 
       if(($postcount % 2) == 0) : // skip 'even' posts 
       $wp_query->next_post(); 
       else : 
       ?> 

       <?php the_post(); ?> 

      <div class="fpost"> 
       <div class="fposttitle"> 
        <h1 class="left"><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'toolbox'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></h1> 
        <?php if (comments_open() || ('0' != get_comments_number() && ! comments_open())) : ?> 
         <div class="combox right"> 
          <?php $x = get_comments_number(); if ($x < 10) : ?> 
           <?php comments_popup_link(__('00', 'toolbox'), __('01', 'toolbox'), __('0%', 'toolbox')); ?> 
          <?php else : ?> 
           <?php comments_popup_link(__('00', 'toolbox'), __('01', 'toolbox'), __('%', 'toolbox')); ?> 
          <?php endif; ?> 
         </div> 
        <?php endif; ?> 
        <div class="clear"></div> 
       </div> 

       <div class="fcontent"> 
        <?php $thumbnail = get_post_meta(get_the_ID(), 'thumbnail', true); 
        if ($thumbnail) : ?> 
         <img src="<?php echo $thumbnail; ?>" alt="<?php the_permalink(); ?>" /> 
        <?php else : ?> 
         <p><?php the_excerpt(); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="finfo"> 
        <p class="left date"><?php the_time('F j, Y') ?></p> 
        <p class="left cat"><?php the_category(', ') ?></p> 
        <p class="right"><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'toolbox'), the_title_attribute('echo=0')); ?>" rel="bookmark" >Read More</a></p> 
        <div class="clear"></div> 
       </div> 
      </div> 

      <?php endif; ?> 
      <?php endwhile; ?> 

     </div><!-- #content --> 

     <div id="holder2" class="left"> 

      <?php while (have_posts()) : ?> 
      <?php 
       $postcount++; 
       if(($postcount % 2) != 0) : // skip 'odd' posts 
       $wp_query->next_post(); 

       else : 
       ?> 

       <?php the_post(); ?> 

      <div class="fpost"> 
       <div class="fposttitle"> 
        <h1 class="left"><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'toolbox'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a></h1> 
        <?php if (comments_open() || ('0' != get_comments_number() && ! comments_open())) : ?> 
         <div class="combox right"> 
          <?php $x = get_comments_number(); if ($x < 10) : ?> 
           <?php comments_popup_link(__('00', 'toolbox'), __('01', 'toolbox'), __('0%', 'toolbox')); ?> 
          <?php else : ?> 
           <?php comments_popup_link(__('00', 'toolbox'), __('01', 'toolbox'), __('%', 'toolbox')); ?> 
          <?php endif; ?> 
         </div> 
        <?php endif; ?> 
        <div class="clear"></div> 
       </div> 

       <div class="fcontent"> 
        <?php $thumbnail = get_post_meta(get_the_ID(), 'thumbnail', true); 
        if ($thumbnail) : ?> 
         <img src="<?php echo $thumbnail; ?>" alt="<?php the_permalink(); ?>" /> 
        <?php else : ?> 
         <p><?php the_excerpt(); ?></p> 
        <?php endif; ?> 
       </div> 

       <div class="finfo"> 
        <p class="left date"><?php the_time('F j, Y') ?></p> 
        <p class="left cat"><?php the_category(', ') ?></p> 
        <p class="right"><a href="<?php the_permalink(); ?>" title="<?php printf(esc_attr__('Permalink to %s', 'toolbox'), the_title_attribute('echo=0')); ?>" rel="bookmark" >Read More</a></p> 
        <div class="clear"></div> 
       </div> 
      </div> 

      <?php endif; ?> 
      <?php endwhile; ?> 

     </div><!-- #content --> 



     <?php else : ?> 

      no post 


    <?php endif; ?> 

     <div class="clear"></div> 
      <div id="nav"> <?php wp_pagenavi() ?> </div> 
    </div><!-- #primary --> 

のための私のコードは、おそらく最後のページので、そこに十分な数のポストではなく、なぜポストリピートを把握することはできません。

update:新しい投稿を1つ追加しようとしましたが、すべて正常に機能します。しかし、別の投稿を追加すると、最後のページが同じ投稿をやり直します。

+0

私はあなたが各ループの前に0にあなたのpostCountをリセットするべきだと思います。 '$ postCount = 0;' –

+0

@BrianGarsonという名前を付けて試してみると、同じ結果が出る前に、 '<?php while(have_posts()):?> –

答えて

1

おそらくコメントの代わりに答えとしてこれを含めるべきでした。あなたが投稿数が奇数の場合、$ postcount変数を0にリセットしないので、2番目のループは必ずしも開始されません最初のループと同じ条件で実行しました。だからあなたの最後のページに、あなたはこの出来事に気づくことができるしている、しかし、チャンスはあなたが完全に特定の記事をスキップしている他のページにあります:

 <?php if (have_posts()) : ?> 

     <?php /* Start the Loop */ ?> 
     <div id="holder" class="left"> 
     <?php $postcount = 0; ?> 
     <?php while (have_posts()) : ?> 
     <?php 
      $postcount++; 
      if(($postcount % 2) == 0) : // skip 'even' posts 
      $wp_query->next_post(); 
      else : 
      ?> 
      <?php the_post(); ?> 
     <?php endif; ?> 
     <?php endwhile; ?> 
     ... 
    </div><!-- #content --> 

    <div id="holder2" class="left"> 
    <?php $postcount = 0; ?> 
     <?php rewind_posts();//rewind the post counter so you can do another loop ?> 
     <?php while (have_posts()) : ?> 
     <?php 
      $postcount++; 
      if(($postcount % 2) != 0) : // skip 'odd' posts 
      $wp_query->next_post(); 

      else : 
      ?> 

      <?php the_post(); ?> 

     ... 

     <?php endif; ?> 
     <?php endwhile; ?> 

    </div><!-- #content --> 
+0

です。どうもありがとうございました。あなたがコメントで言いますと、それを間違った場所に置いていたかもしれません。ありがとう –

+0

私はそれがそれぞれのループの前に両方とも0に設定されていると思います。 NP :) –

関連する問題