Risposte nei forum create
-
AutorePost
-
cescoPartecipante
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.
cescoPartecipanteHo 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…
cescoPartecipanteLa soluzione è molto più banale di come appare… ho semplicemente riscritto in HTML una parte del file sidebar.php nella cartella del tema, per far apparire i link nell’ordine che desideravo (tanto è per un sito di un amico fotografo, non aggiungerà mai nuove pagine per conto suo…)
cescoPartecipanteE’ molto semplice, immagina di dover aggiungere il supporto multilingua al sito “www.pippo.com” e di utilizzare un tema / template grafico denominato “il_tema_di_pippo”.
Nella cartella contenente il tema (wp-content/themes/il_tema_di_pippo) basta inserire un file denominato “home.php”, in cui metteremo la classica selezione della lingua… qualche bandierina colorata e ad esempio un paio di link per aprire il sito in Italiano e Inglese.
Non appena WordPress si accorgerà dell’esistenza di home.php, lo visualizzerà sempre e comunque come pagina di apertura del nostro sito. Ovvero, ogni volta in cui in un browser aprirò il sito “www.pippo.com”, automaticamente mi apparirà la pagina web contenuta in home.php *PRIMA* di visualizzare il nostro blog wordpress vero e proprio.
Ma torniamo al funzionamento: il plug-in per poter lavorare ha bisogno di sapere in quale lingua deve visualizzare i post. Per passargli la lingua utilizziamo una variabile denominata “l” attraverso il metodo GET. Che in soldoni significa che se per aprire il mio sito internet in genere scrivo:
In questo caso dovrò aggiungere la variabile “l” all’indirizzo del mio sito. L’indirizzo da richiamare cosଠdiventerà :
Che in questo caso aprirà il sito http://www.pippo.com e gli passerà la variabile “l” con valore “it”.
Capisci bene che a questo punto per aprire il sito in Italiano e Inglese basta inserire i due link cosà¬:
(che visualizzerà il sito in Italiano)
(che visualizzerà il sito in Inglese)
cescoPartecipanteIn pratica questo è il codice per realizzare il mio plug-in.
Amanti del codice ben strutturato e ottimizzato, inorridite di fronte a questo pastrocchio
Puoi scaricarlo qui
cescoPartecipanteProbabilmente ti conviene scrivere qualcosa di tuo per farlo. Io mi sono scritto per conto mio un plug-in molto semplice in pochissimo tempo.
In pratica nei post racchiudo le varie traduzioni fra i tag [IT] e [/IT] per quello che voglio appaia quando seleziono la lingua italiana, [EN] e [/EN] per la lingua inglese, e cosଠvia per le altre lingue.
Ad esempio se voglio scrivere un post multilingua scrivo:
[IT]Ciao questa è una prova[/IT][EN]Hi this is a test[/EN]
e a seconda della lingua in cui decido di visualizzare il sito (decisa da una variabile passata tramite GET) visualizzo la scritta in Italiano o in Inglese. Quando invece ho bisogno di inserire una frase in più lingue nella template della pagina, richiamo la funzione “Multilingua” con le varie traduzioni per parametro. Ad esempio:
<?php echo Multilingua(“Buongiorno”, “Good Morning”, “Bonjour”); ?>
Vista la semplicità del plug-in, che si limita a sostituire il testo compreso nei tag ci ho messo meno di un’ora a scriverlo. Ci saranno sicuramente metodi più eleganti, ma a me serviva la praticità e credo di averla trovata.
cescoPartecipanteOk, ho messo online il tema MistyLook tradotto in Italiano. Potete scaricarlo da questo link:
cescoPartecipanteSiccome con WordPress sono alle prime armi ho tradotto le frasi in inglese presenti nel codice sorgente del programma, mantenendo gli altri termini in inglese presenti nei comandi _e(“<< PAROLA IN INGLESE >>”) che da quello che ho capito vengono direttamente tradotti dalla template italiana di WP.
-
AutorePost