Perché WP_Query('showposts=5') mostra solo 1 articolo?
Sto cercando di fare una semplice query per ottenere gli ultimi 5 articoli in una lista non ordinata, ma questa mostra solo 1 risultato nonostante io abbia diversi post. Ho anche provato con l'offset, ma mostra solo il post successivo e comunque un solo risultato. Cosa sto sbagliando?
<ul>
<?php $the_query = new WP_Query('showposts=5'); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<p><?php the_content_limit(250); ?></p>
</li>
<?php endwhile;?>
</ul>

the_content_limit
non esiste in WordPress. Probabilmente stai cercando qualcosa come the_excerpt
.
Quello che probabilmente sta accadendo è che il tuo loop funziona correttamente, ma la chiamata a una funzione non definita causa un errore nel programma, facendo sembrare che il loop non funzioni. Guarda l'HTML renderizzato: probabilmente vedrai un singolo tag <li>
di apertura, il link e un tag di paragrafo aperto.
showposts
è anche deprecato. Dai un'occhiata nel codex: rimosso nella versione 2.1
Prova questo:
<?php
$query = new WP_Query(array(
'posts_per_page' => 5,
));
while ($query->have_posts()): $query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p><?php the_excerpt(); ?></p>
</li>
<?php endwhile;

La sintassi predefinita per post_per_page è:
<?php
$query = new WP_Query
(array(
'posts_per_page' => 5, // Numero di articoli da visualizzare
)
);
while ($query->have_posts()): $query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<p><?php the_excerpt(); ?></p>
</li>
<?php endwhile;

showposts
è stato sostituito da posts_per_page
. Per favore leggi la risposta accettata

Sì, funziona, ma è deprecato e potrebbe essere rimosso in futuro, il che potrebbe compromettere il tuo sito
