Home › Forum › Problemi Vari con WP › immagini fuori dal loop
-
AutorePost
-
-
31 Ottobre 2008 alle 17:32 #8368andreacutelliPartecipante
salve a tutti.
che voi sappiate.. é possibile caricare una immagine come se dovesse essere inserita nell’articolo (o nella pagina) ma farla invece comparire al di fuori del loop..?
grazie mille!!!
-
31 Ottobre 2008 alle 18:13 #59022wollyAmministratore del forum
con questo codice, che mi ha mandato matt mullenweg per email, estraggo un immagine a caso fuori dal loop dai miei post:
<?php $hilite = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY RAND() LIMIT 1" ); echo '' . wp_get_attachment_image( $hilite, 'thumbnail' ) . ''; ?>
-
31 Ottobre 2008 alle 22:42 #59032andreacutelliPartecipante
wolly, innanzitutto grazie per la cortesia ma ho provato con il codice che hai scritto ma non mi funziona..
sto usando per necessità , la versione 2.5 di wp ma non riesco a venire a capo di una soluzione qualsiasi..
e cmq, non devo visualizzare un’immagine qualunque ma esattamente quella che carico assieme all’articolo.
..non credo di farcela )
-
1 Novembre 2008 alle 23:07 #59045andreacutelliPartecipante
ho risolto in questo modo.. probabilmente poco elegante ma molto funzionale.
ho inserito nel file functions.php la seguente stringa:
function get_img_link($stringa) {
$pattern = "";
preg_match($pattern, $stringa, $img);
$img_url = $img[2];
return $img_url;
}
e nei files single.php e archive.php ho aggiunto la chiamata:
" alt="" />
in questo modo, inserendo testo ed immagine in un unico articolo, é possibile visualizzarli separatamente in 2 punti diversi della pagina.
si poteva ovviare comodamente con i CSS attribuendo dei parametri di "posizionamento" assoluti o relativi ma non tutti i browser li avrebbero interpretati correttamente.
spero possa essere d'aiuto a qualcuno!
saluti.
-
1 Novembre 2008 alle 23:16 #59046andreacutelliPartecipante
< img src=”<? php echo get_img_link(get_the_content()); ?>” alt=”” />
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.