[英]wordpress posts_per_page incorrect display
我有個問題。 我想用這段代碼展示一次一篇文章,一次展示5篇文章,但是他展示了兩個比必要更多的內容。 我沒有得到的是,這是我的另一個主題相同的網站,但確實有效。 完全相同的主題只有其他網站。 誰能幫我?! (檢查錯誤的結果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();
?>
問題是您的查詢返回的是粘性帖子,無論出於何種原因,這些帖子都會被粘貼到帖子限制中,而不是作為該限制的一部分。 將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.