Home › Forum › Problemi Vari con WP › Custom Home Page – Home page personalizzata
-
AutorePost
-
-
25 Agosto 2011 alle 12:27 #18946NappaPartecipante
Ciao, ho ancora bisogno di voi.
Ho creato una home page personalizzata, dove scelgo io gli articoli da visualizzare.
Per farlo ho usato un plugins, Featured post list2, che visualizza nell’amministrazione un campo dove posso inserire, divisi da virgole, gli ID degli articoli che mi voglio visualizzare (tutto questo finché non riesco a creare un’impostazione io personalmente).
Nella mia pagina, richiamo la funzione che mi ritorna un array con i numeri degli articoli (es: 1,15,10,60,42), li prendo uno per uno e li visualizzo.
Ecco il problema, nonostante escludo l’ordinamento degli articoli, WP me li mette in ordine di data e non in ordine in cui sono inseriti nell’array.
Qualcuno può aiutarmi? di seguito il codice sorgente con i commenti.
Grazie, Nap
$fellback_array = featuredpostsList2Nap (); // chiama la funziona modificata NAP e restituisce l’array indicato nel setting del plug in (es: 1,15,10,60,42).
$my_query = new WP_Query();
$my_query->query(array( ‘orderby’ => ‘none’, ‘post__in’ => $fellback_array,)); // prende solo gli id che gli ho indicato
// LOOP che mette i thumnails
while ($my_query->have_posts()) : $my_query->the_post();
… the_post_thumbnail(‘gallery-big315’);
endwhile;
wp_reset_query();
?>
-
25 Agosto 2011 alle 12:40 #87759AndreamkPartecipante
Fai confusione orderby none semplicemente toglie l’orderby dalla query sql.
A lato pratico vuol dire che gli articoli vengono visualizzati in ordine di creazione quindi neanche per ordine di data dell’articolo ma proprio di creazione dell’articolo.
Infatti in teoria se cambi data dell’articolo vedreai che l’ordine non cambia.
Ipotizzando che in $fellback_array ci sia l’elenco degli id che ti interessano in modo ordinato devi fare il loop su $fellback_array e andarti a pescare a mano i vari post.
-
25 Agosto 2011 alle 15:03 #87763NappaPartecipante
…quindi tu suggerisci di fare una query per ogni post ID?… ci provo
grazie
-
25 Agosto 2011 alle 16:02 #87766NappaPartecipante
trovato questo post su WP.org
http://wordpress.org/support/topic/how-to-query-a-post-using-post-id-from-a-specific-post_type
-
25 Agosto 2011 alle 18:44 #87769AndreamkPartecipante
Una query per ogni id è veramente poco ottimizzato anche se funziona.
Io farei una query con tutti gli id e poi per ogni id nell’array mi andrei a cercare nel risultato della query il post giusto.
$fellback_array = featuredpostsList2Nap ();
$my_query = query_posts(array('post__in' => $fellback_array));
$postsById = array();
foreach ($fellback_array as $cId) {
$postsById[$cId] = null;
}
foreach ($my_query as $cPost) {
if (isset( $postsById[$cPost->ID]) {
$postsById[$cPost->ID] = $cPost;
}
}
global $post;
foreach ($postsById as $cId => $post) {
setup_postdata($post);
// questo è il loop degli articoli
...
the_title();
the_content();
...
}
L’ho scritto dirttamente qui e non è stato testato ma la logica è questa.
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.