为什么get_posts只显示五个帖子(通过为其分配类别来检索?


10

链接在这里

http://www.brianfunshine.com/voice-work/voice-page/

这是代码:

<?php
/**
 * Template Name: Voice Page (Two Columns)
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */

get_header(); ?>


<?php breadcrumb(); ?>

<?php // this is the main loop ?>
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>

<div class="top-column">

    <div class="post">

        <h2 class="post-title">
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        </h2>

        <div class="entry">
            <?php the_content(); ?>
        </div>

        <div class="post-meta-data">
            <?php wp_link_pages('before=<p>'.__('Pages:','options').'&after=</p>'); ?>
        </div>

    </div>

    <?php endwhile; ?>

<?php else: ?>

    <p><?php _e('Sorry, no posts matched your criteria.','options'); ?></p>

<?php endif; ?>

</div><!-- .top-column -->

<div class="left-column">

<?php // retrieve a list of posts with category Voice Audio Demos
$args = array('category_name' => 'Voice Page (Left Column)', 'order' => 'DESC', 'posts_per_page'=>-1);
$customposts = get_posts($args);
foreach($customposts as $post) : setup_postdata($post); ?>

    <div class="post">

        <h2 class="post-title">
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        </h2>

        <div class="entry">
            <?php the_content(); ?>
        </div>

    </div>

<?php endforeach; ?>

</div><!-- .left-column -->

<div class="right-column">

<?php // retrieve a list of posts with category Voice Audio Demos
$args = array('category_name' => 'Voice Page (Right Column)', 'orderby' => 'DESC', 'posts_per_page'=>-1);
$customposts = get_posts($args);
foreach($customposts as $post) : setup_postdata($post); ?>

    <div class="post">

        <h2 class="post-title">
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        </h2>

        <div class="entry">
            <?php the_content(); ?>
        </div>

    </div>

<?php endforeach; ?>

</div><!-- .left-column -->

<?php get_footer(); ?>

它仅检索类别为“语音页面(左列)”和“语音页面(右列)”的帖子。我在该类别中有5条以上的帖子,但该页面仅显示5条:

在此处输入图片说明

Answers:


24

如果查看get_posts Codex上的文档,则可以看到要显示的帖子数的参数:

$ numberposts(整数)(可选)要返回的帖子数。设置为0以使用每页的最大帖子数。设置为-1以消除限制。

默认值:5

这就是为什么它仅显示5条帖子。您需要将参数添加到args数组中:

$args = array(
    'category_name' => 'Voice Page (Right Column)', 
    'orderby' => 'DESC', 
    'posts_per_page'=>-1, 
    'numberposts'=>-1
);

同样来自法典,Note: 'numberposts' and 'posts_per_page' can be used interchangeably.
tehlivi
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.