【发布时间】:2011-08-16 03:19:59
【问题描述】:
大家好。我不确定我遇到的问题是由于错误(由于最近升级到 3.1.2)还是编码不佳造成的。自从我升级到 3.1.2 版后,我的索引页面上出现了两个循环问题。
这是我的索引页的内容
<?php
if ( ! is_paged() && is_front_page() ) {
echo '<h6 class="sec1 title">FEATURE</h6>';
$sticky = get_option( 'sticky_posts' );
if ( isset( $sticky[0] ) ) {
$args = array(
'posts_per_page' => 3,
'post__in' => $sticky,
'ignore_sticky_posts' => 1);
// Query
$featured_query = new WP_query( $args );
while ($featured_query->have_posts() ) :
$featured_query->the_post();
$featured[] = $post->ID;
get_template_part( 'content', 'featured' );
endwhile;
} // endif sticky
} // endif is_paged
?>
<?php
$sticky = get_option( 'sticky_posts' );
echo '<h6 class="sec1 title">LATEST ARTICLES</h6>';
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$query_args = array(
'posts_per_page' => 10,
'paged' => $paged,
'post__not_in' => $featured,
'post__not_in' => $sticky
);
query_posts($query_args);
if (have_posts() ) :
while (have_posts() ) :
the_post();
get_template_part( 'content', get_post_format() );
?>
<!--<?php trackback_rdf(); ?>-->
<?php endwhile; else: ?>
<div class="box">
<p>
<?php _e( 'Sorry, no posts matched your criteria.' ); ?>
</p>
</div>
<?php endif; ?>
// Navigation comes over here
例如第一个循环 (置顶帖子) - 没有分页,产生 3 个帖子,第二个循环 (所有其他帖子) - 分页,产生 10 个帖子。我遇到的问题是,当我转到下一页时,第 1 页第二个循环中的最后 3 个帖子 在第 2 页的顶部重复出现。
注意:第一个循环仅在第 1 页上,并且不会在第二页上重复,这是我的意图。
这就是我尝试的方法,我删除了 (!is_paged() && is_front_page) 条件以及整个第一个循环,问题得到了解决。
我做错了什么?
【问题讨论】:
标签: wordpress loops pagination