WordPress没有显示超过10个帖子

时间:2014-01-20 10:37:17

标签: wordpress

我正在通过短代码向WordPress的帖子/页面显示帖子,并希望显示无限的帖子列表,但它只显示10个帖子。

这是我的代码;请指导我查询有什么问题。

$args = array( 'post_type' => 'post', 'cat' => '2', 'meta_key' => 'issue_of_article', 'meta_value' => $issue, 'posts_per_page' => -1, 'orderby' => 'artcle_category', 'order' => 'ASC');
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
     $loop->the_post();
     <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
endwhile;
}

5 个答案:

答案 0 :(得分:11)

只需在你的论点中添加它

'posts_per_page' => -1

然后你就完成了。

还有一件事:您可以将默认设置从管理员更改为10以外的其他设置。转到WordPress管理员 - 设置 - 阅读。有一个选项,如“博客页面最多显示”。在那里键入您想要的帖子数量作为默认值。

答案 1 :(得分:1)

转到管理页面中的设置菜单

设置 - &gt;读 更改博客页面最多显示的值。

它会起作用。

答案 2 :(得分:0)

愚蠢的问题可能但你为什么叫$ loop-&gt; the_post();两次?这不是问题的根源吗? (每个循环一次调用2个帖子)

答案 3 :(得分:0)

1)首先,我建议始终在Wordpress.Stackexchange.com

发帖

2)最好的方法是添加 functions.php

add_action('pre_get_posts','myfunc');
function myfunc($query){ 
    if ($query->is_main_query() && $query->is_archive){
        $query->set( 'posts_per_page', 1000);
    }
    return $query;
}

答案 4 :(得分:0)

'posts_per_page' => -1

'posts_per_page' => 1000

这两个都应该有用。

相关问题