[英]wordpress posts_per_page incorrect display
I have a problem. 我有个问题。 I would like to show one time one post and one time 5 posts with this code but he shows two porst more than necessary.
我想用这段代码展示一次一篇文章,一次展示5篇文章,但是他展示了两个比必要更多的内容。 What I don't get, is that it's another site of me with the same theme does work.
我没有得到的是,这是我的另一个主题相同的网站,但确实有效。 The completely same theme only a others website.
完全相同的主题只有其他网站。 Who can help me?!
谁能帮我?! (check the wrong result http://radiozuid.com/ an websie correct result http://radiozuid.rtv-zuid.com/beta/ ) (Exact same theme)
(检查错误的结果http://radiozuid.com/一个websie正确的结果http://radiozuid.rtv-zuid.com/beta/ )(完全相同的主题)
<?php
$the_query = new WP_Query(array(
'posts_per_page' => 1
));
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>
<div class="item active">
<?php if(has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'small-nivo-thumb'); ?>
<img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $image[0]; ?>&w=620&h=350" class="postafbeelding" alt="<?php the_title(); ?>">
<?php else: ?>
<img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo get_template_directory_uri(); ?>/images/thumbnail.png&w=620&h=350" class="postafbeelding" alt="<?php the_title(); ?>">
<?php endif; ?>
<div class="carousel-caption">
<h3 class="titel"><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h3>
<p><?php echo string_limit_words(get_the_excerpt(), 35); ?>...<a href="<?php the_permalink(); ?>" rel="tooltip" data-original-title="Lees Meer" class="leesmeer"> Lees Meer</a></p>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
<?php
$the_query = new WP_Query(array(
'posts_per_page' => 5,
'offset' => 1
));
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>
<div class="item">
<?php if(has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'small-nivo-thumb'); ?>
<img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo $image[0]; ?>&w=620&h=350" class="postafbeelding" alt="<?php the_title(); ?>">
<?php else: ?>
<img src="<?php echo get_template_directory_uri(); ?>/timthumb.php?src=<?php echo get_template_directory_uri(); ?>/images/thumbnail.png&w=620&h=350" class="postafbeelding" alt="<?php the_title(); ?>">
<?php endif; ?>
<div class="carousel-caption">
<h3 class="titel"><a href="<?php the_permalink(); ?>"><?php the_title();?></a></h3>
<p><?php echo string_limit_words(get_the_excerpt(), 35); ?>...<a href="<?php the_permalink(); ?>" rel="tooltip" data-original-title="Lees Meer" class="leesmeer"> Lees Meer</a></p>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
The problem is that your query is returning sticky posts, which for whatever reason are tacked onto the post limit rather than counting as part of it. 问题是您的查询返回的是粘性帖子,无论出于何种原因,这些帖子都会被粘贴到帖子限制中,而不是作为该限制的一部分。 Add
ignore_sticky_posts
to your query and I think that will fix it. 将
ignore_sticky_posts
添加到您的查询中,我认为它将解决此问题。
$the_query = new WP_Query(array(
'posts_per_page' => 5,
'offset' => 1,
'ignore_sticky_posts' => true
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.