Perché get_posts mostra solo cinque post (recuperati assegnando loro una categoria)?

26 gen 2011, 16:16:45
Visualizzazioni: 22K
Voti: 11

Ecco il link

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

Questo è il codice:

<?php
/**
 * Nome Template: Voice Page (Due Colonne)
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */

get_header(); ?>


<?php breadcrumb(); ?>

<?php // questo è il loop principale ?>
<?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>'.__('Pagine:','options').'&after=</p>'); ?>
        </div>

    </div>

    <?php endwhile; ?>

<?php else: ?>

    <p><?php _e('Spiacenti, nessun post corrisponde ai tuoi criteri.','options'); ?></p>

<?php endif; ?>

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

<div class="left-column">

<?php // recupera una lista di post con categoria 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 // recupera una lista di post con categoria 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(); ?>

Recupera solo i post con categoria Voice Page (Left Column) e Voice Page (Right Column). Ho più di 5 post in quella categoria ma la pagina ne mostra solo 5:

Schermata che mostra solo 5 post recuperati dalla categoria

0
Tutte le risposte alla domanda 1
1
26

Se guardi la documentazione di get_posts sul Codex, puoi vedere che c'è un parametro per il numero di post che vuoi visualizzare:

$numberposts (intero) (opzionale) Numero di post da restituire. Impostare a 0 per usare il numero massimo di post per pagina. Impostare a -1 per rimuovere il limite.

Predefinito: 5

Ecco perché vengono visualizzati solo 5 post. Devi aggiungere il parametro al tuo array args:

$args = array(
    'category_name' => 'Voice Page (Right Column)', 
    'orderby' => 'DESC', 
    'posts_per_page'=>-1, 
    'numberposts'=>-1
);
26 gen 2011 16:26:29
Commenti

Anche dal Codex, Nota: 'numberposts' e 'posts_per_page' possono essere usati in modo intercambiabile.

tehlivi tehlivi
24 mar 2017 17:20:12