2012-03-05 2 views
0

나는 두 개의 열을 사용하여 내 게시물을 표시하려고 서로 맞는, 내가 두 개의 수직 열을 만들려고 노력하고, 홀수와 심지어 별도로 표시합니다. 왼쪽은 홀수, 오른쪽은 홀수입니다. 그리고 wp_pagenavi()를 사용하여 탐색 작업을 수행하고, 다른 페이지가 잘 작동하고, 의도대로 게시물을 표시하지만, 마지막 페이지에서는 한 번의 게시물이 두 번 반복됩니다.Wordpress 게시물 마지막 페이지에서 두 번 반복

여기에 내가 생각 루핑 부분

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

내 코드는 어쩌면 마지막 페이지 있기 때문에, 거기에 충분한 수의 포스트 아니라, 왜 포스트 반복을 알아낼 수 없습니다.

업데이트 : 새 게시물을 하나 추가하려고했는데 모든 것이 잘 작동합니다. 하지만 다른 게시물을 추가하면 마지막 페이지가 같은 게시물을 반복합니다.

+0

난 당신이 각 루프 전에 0에 postCount를 재설정한다고 생각합니다. '$ postCount = 0;' –

+0

@BrianGarson을 포함하지 않으면 안되며, 시도해 보았지만 여전히 같은 결과를 내지 못합니다. –

답변

1

아마도 답장으로 답장을 포함해야합니다. 홀수 개의 게시물이있는 경우 $ postcount 변수를 0으로 재설정하지 마십시오. 따라서 두 번째 루프가 시작되지 않아도됩니다 첫 번째 루프와 동일한 조건으로 그래서 마지막 페이지에서 당신은 이런 일을 알 수있어,하지만 기회는 당신이 모두 특정 게시물을 생략하고 다른 페이지에 있습니다

 <?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 :) –

관련 문제