这是我索引页面的内容
<?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个帖子,第二个循环(所有其他帖子)< / em> - 对其进行分页,产生 10个帖子。我遇到的问题是,当我移动到下一页时,第1页第二个循环中的最后 3个帖子会在第2页的顶部重复出现。
注意:第一个循环仅在第1页上,并且不会在第二页上重复,这正是我想要的。
所以这就是我尝试的,我删除了(!is_paged()&amp;&amp; is_front_page)条件以及整个第一个循环,问题得到了解决。
我做错了什么?
答案 0 :(得分:1)
在第一次循环后,尝试添加 wp_reset_postdata();
我不确定你是否尝试在第一页上只有第一个循环,但如果你是,请尝试类似
$paged = get_query_var('page');
if ($paged < 2) :
// Put whatever you want to only show up on the first page here
endif;
答案 1 :(得分:1)
谢谢Chris,
我改变了你的建议(似乎没有用)
$paged = get_query_var('page');
if ($paged < 2) :
// Put whatever you want to only show up on the first page here
endif;
到
$paged = get_query_var('paged');
if ($paged < 1 ) {
// code goes here
}
似乎第一页不被视为“分页”..“分页”仅适用于第一页以外的页面。
这是任何感兴趣的人的更新代码。给克里斯的帽子小费。再次感谢。
$paged = get_query_var('paged');
if ($paged < 1 ) {
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();
get_template_part( 'content', 'featured' );
endwhile;
wp_reset_postdata();
} // endif sticky
} // endif $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' => $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; ?>
上一个例子的替代方案是我在Chris回答之前从头开始构建的
<?php if ( isset( $sticky[0] ) && ! is_paged() ) {
echo '<h6 class="sec1 title">FEATURE</h6>';
} ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php if ( is_sticky() ) {
get_template_part( 'content', 'featured' );
} ?>
<?php endwhile; ?>
<?php rewind_posts(); ?>
<?php
echo '<h6 class="sec1 title">LATEST ARTICLES</h6>';
global $sticky;
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array(
'posts_per_page' => 10,
'paged' => $paged,
'post__not_in' => $sticky
);
query_posts( $args );
while ( have_posts() ) :
the_post() ;
?>
<?php get_template_part( 'content', get_post_format() ); ?>
<!--<?php trackback_rdf(); ?>-->
<?php endwhile; ?>
答案 2 :(得分:0)