[英]Wordpress -> nesteed post loop does not return the number of posts specified in 'posts_per_page' parameter
[英]Wordpress loop “posts_per_page=4” shows only 1 post
我有一個循環要檢查
是否選中了自定義字段(復選框),並且
如果隨后的循環中有內容。
現在我不明白為什么循環總是只顯示一個帖子:
<?php
//check if field has content
if(get_field("news_kategorie")): ?>
<ul class="page-articles-related">
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('posts_per_page=6&orderby=date&category_name='.implode (',',get_field('news_kategorie'))); ?>
<?php
//check if loop has content
if ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<li class="relativ">
<?php the_title(); ?>
</li>
<?php else: { ?>
<?php echo "There is nothing ..."; ?>
<?php } ?>
<?php endif; ?>
</ul>
<?php endif; ?>
除了posts_per_page=6
之外, posts_per_page=6
所有東西都正常,我總是看到一則帖子,但我想顯示六篇帖子。
您當前的代碼僅打印一篇文章,這應該打印所有六篇文章:
if ($wp_query->have_posts()) : $wp_query->the_post();
while ( have_posts() )
{
?>
<li class="relativ">
<?php the_title(); ?>
</li>
<?php
} // end while
在標題中,您說每頁需要4個帖子,但是在實際問題中,您希望有6個帖子,這是什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.