나는 두 개의 열을 사용하여 내 게시물을 표시하려고 서로 맞는, 내가 두 개의 수직 열을 만들려고 노력하고, 홀수와 심지어 별도로 표시합니다. 왼쪽은 홀수, 오른쪽은 홀수입니다. 그리고 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에 postCount를 재설정한다고 생각합니다. '$ postCount = 0;' –
@BrianGarson을 포함하지 않으면 안되며, 시도해 보았지만 여전히 같은 결과를 내지 못합니다. –