Scorrere attraverso i post in modo semplice
22 dic 2011, 22:13:25
Visualizzazioni: 64.7K
Voti: 9
So che questa è una domanda da principiante, ma non riesco a far sì che il loop estragga i post. Tutto quello che fa è estrarre dalla pagina stessa.
Ho creato un template e ho aggiunto il loop.
<?php
// Se ci sono post da mostrare
if( have_posts() ) {
// Cicla attraverso i post
while( have_posts() ) {
the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
modifica: ecco tutto il codice: http://pastebin.com/k2rDu53b

user766607
95
Commenti
Mostra i restanti 1 commenti
Tutte le risposte alla domanda
1
1
Poiché ti trovi in una pagina che visualizzerà solo la query per quella specifica pagina. Di conseguenza, dovrai creare una nuova query per includere gli articoli che desideri. Sostituisci il tuo loop con questo:
<?php
$args = array(
'post_type' => 'post'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
Qui trovi ulteriori informazioni sulla query: http://codex.wordpress.org/Class_Reference/WP_Query

CookiesForDevo
1.14K
23 dic 2011 00:25:38
Commenti
Alla fine, dovresti resettare la query con wp_reset_postdata();
https://codex.wordpress.org/Function_Reference/wp_reset_query

18 mar 2017 18:00:17
Domande correlate
4
risposte