我嘗試使用兩個列,以確保彼此配合,以顯示我的帖子,我試圖創建兩個垂直列,並顯示後奇數和偶數seperately。奇數在左側,甚至在右側。並且爲了讓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 -->
我想代碼也許是因爲最後一頁,沒有足夠數量的職位,但無法弄清楚,爲什麼後重復。
更新:我只是想添加一個新的崗位,一切工作正常。但是當我添加另一篇文章時,它的最後一頁再次重複相同的文章。
我認爲你應該每個循環之前你postCount重置爲0。在'<?php while(have_posts()):?>'你應該包含'$ postCount = 0;' – 2012-03-05 17:20:37
@BrianGarson nope,嘗試它,不起作用仍然是相同的結果。它的工作原理是 – 2012-03-05 17:25:09