問題描述

鏈接在這裏

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="http://<?php%20the_permalink();%20?>" 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="http://<?php%20the_permalink();%20?>" 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="http://<?php%20the_permalink();%20?>" 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 個帖子 bu 頁面只顯示 5:

最佳解決方案

如果你看看 get_posts documentation on Codex,你可以看到你想顯示的帖子數量有一個參數:

$numberposts (integer) (optional) Number of posts to return. Set to 0 to use the max number of posts per page. Set to -1 to remove the limit.

Default: 5

這就是為什麼它只顯示 5 個帖子。您需要將參數添加到 args 數組中:

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

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。