WordPress返回的默认结果数

时间:2012-02-17 16:02:28

标签: wordpress

由于某些原因,此查询仅返回最近发布的10个结果,因此应该至少有15个左右。所以我的问题是,如果我没有在查询中指定结果数量,WordPress会默认为10还是什么?

<?php getGallery('test', 'test2'); ?>


function getGallery($galleryLink, $altLink){

    global $post;

    // search for any pages with a custom field of 'test'
    query_posts('meta_key='.$galleryLink.'&post_type=page');

    if (have_posts()) while (have_posts()) : the_post();
        $link = get_post_meta($post->ID, $galleryLink, true); 
        $alt = get_post_meta($post->ID, $altLink, true);
        $permalink = get_permalink($id);?>

    <a href='<?php echo $permalink ?>'><img src="<?php echo $link ?>" alt="<?php echo  $alt ?>"/></a>

    <?php endwhile;

    wp_reset_query();
}

4 个答案:

答案 0 :(得分:1)

是。标准Loop查询显示WordPress中“阅读设置”页面中定义的帖子数量,默认为10个。

如果要以编程方式更改此选项,请参阅the WP_Query documentation中“分页参数”下的示例,而不是依赖于该设置。例如:

$query = new WP_Query( 'posts_per_page=-1' );

...将检索所有帖子。

答案 1 :(得分:1)

$ wp_query中的默认退回帖子数量在Dashboard&gt;中定义。设置&gt;读。你已经定义了10,但请记住,其他人可以在他们的博客上设置不同的数字。

我希望你知道,如果你想定义自己的帖子数量,你应该将posts_per_page = X添加到查询:)如果你想总是返回匹配查询的所有帖子-1代替X

答案 2 :(得分:1)

您应该能够将默认值10修改为您在查询中使用posts_per_page参数指定的任何数字,如下所示:

query_posts('meta_key='.$galleryLink.'&post_type=page&posts_per_page=20');

以您喜欢的任何值代替20而不是20.更好的是,使用变量并远离文字。

答案 3 :(得分:0)

如果这是您的默认循环,只需转到设置 - &gt;阅读并更改“博客页面最多显示”到您想要的号码。如果您指定的数字少于您的帖子总数,则必须包含某种导航,以允许访问者访问之前的帖子。

相关问题