Home › Forum › Problemi Vari con WP › Visualizzare i post recenti nella sidebar
-
AutorePost
-
-
23 Marzo 2007 alle 16:25 #3456cescoPartecipante
Ciao, esiste una funzione interna di WordPress che mi permetta di visualizzare una lista dei post recenti da me pubblicati ? Mi spiego meglio…
Facciamo finta che sul mio blog io abbia inserito 10 articoli e decida di farne visualizzare solo cinque per pagina. C’e’ un modo per far visualizzare, in piccolo sulla sidebar, dei link ai restanti post (quindi dal sesto al decimo post non visualizzati) ?
Qualcosa sul genere (invento spudoratamente una funzione inesistente) <?php wp_list_post(“title”, 6, 5); ?> che mi permetta di visualizzare la lista degli ultimi 5 post a partire dal sesto
Grazie mille
-
23 Marzo 2007 alle 17:46 #43989cescoPartecipante
Ho provato anche a scrivere
$my_query = new WP_Query('showposts=10&offset=2');
while ($my_query->have_posts()) : $my_query->the_title();
endwhile;
Ma non succede assolutamente un cacchio…
-
23 Marzo 2007 alle 21:35 #43995andreaPartecipante
Puoi provare con la funzione
wp_get_recent_posts();
Altre informazioni utili le trovi ad esempio in questa discussione.
-
24 Marzo 2007 alle 8:11 #43997cescoPartecipante
Grazie.
Ho trovato questo codice:
$today = current_time('mysql', 1);
$results = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 10");
foreach ( $results as $result )
echo "<li><a href="".get_permalink($result['ID'])."">".$result['post_title']."</a></li>";
Che però sul mio server non funziona (dice che la variabile $result non può restituire un valore di tipo array) ed in più oltre agli articoli visualizza anche le pagine fisse.
Ho modificato lo script in questo modo:
$today = current_time('mysql', 1);
$risultati = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5, 10");
foreach ( $risultati as $risultato )
echo '<li><a href="'. get_permalink($risultato->ID). '"><img src="' . get_bloginfo('template_url') . '/images/navbulle.png" alt="#" border="0"> ' .$risultato->post_title . '</a></li>';
e adesso sembra funzionare, visualizzandomi solo gli articoli.
Cambiando nella query SQL il valore LIMIT 10 (ultimi 10 articoli) con LIMIT 5, 10 (ultimi 10 articoli a partire dal quinto) riesco a ottenere quello che volevo.
L’ultima cosa fica che mi mancherebbe è quella di sapere se esiste una variabile di wordpress che mi permetta di sapere quanti articoli vengono visualizzati per pagina, in modo da poter metterci un LIMIT $MAX_ARTICOLI + 1, 10 e andare sempre sul sicuro
Grazie ancora.
-
24 Marzo 2007 alle 17:37 #44002andreaPartecipante
Puoi ottenere il numero di post per pagina con
get_option('posts_per_page');
-
25 Marzo 2007 alle 14:19 #44008cescoPartecipante
Grazie mille
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.