Home › Forum › Problemi Vari con WP › Query su Media Library
-
AutorePost
-
-
18 Aprile 2011 alle 22:24 #17597NappaPartecipante
Ciao a tutti, vorrei fare un imagescroller prendendo a caso le immagini dal DB della libreria dei Media.
Sono arrivato fino alla query, ma poi non so che farci del risultato.
una cosa tipo: SELECT * FROM wp_postmeta WHERE wp_postmeta.meta_key = ‘_wp_attached_file’
Ho cercato dappertutto, ma senza trovare riferimenti su come prendere le immagini dalla Libreria dei Media senza inserirli nei post.
Spero che qualcuno abbia qualche indizio.
Wordpress ver 3.1.1
Grazie a tutti
Nap
-
19 Aprile 2011 alle 7:20 #83590SteveAglAmministratore del forum
le immagini allegate sono dei tipi di post quindi li trovi nella tabella dei post come post type atachement… li con id e tutto risaly al loro link etc etc… poi dipende che devi farci e come con che regola.. una immagine per articolo associare le info dell’articolo padre etc etc
-
19 Aprile 2011 alle 7:22 #83591SteveAglAmministratore del forum
ma direi che non dovresti aver bisogno di query dirette.. ma devi dettagliare che vuoi fare esattamente e con che criteri.
-
19 Aprile 2011 alle 7:41 #83597wollyAmministratore del forum
$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’ ) . ‘‘;
-
19 Aprile 2011 alle 12:54 #83620NappaPartecipante
… devo dire che wordpress è un prodotto fantastico, ma anche le persone che lo usano lo sono
Grazie infinite per la soluzione, è proprio quello che mi serviva…
mi rimane solo un dubbio:
Avrei bisogno di selezionare più di una immagine a caso (direi 6), riesci a scrivermi la sintassi?
grazie 1000…
altra cosina, ma penso di cavarmela con qualche ricerca, le immagini devono essere strette e alte, quindi ho aggiunto del codice nel file function.php del tema per aggiungere un thumbnail diverso.
80×195 facendo un hard crop, ma ovviamente non funzia
add_image_size( ‘scroll-thumbnail’, 80, 195, true );
-
19 Aprile 2011 alle 13:30 #83621wollyAmministratore del forum
metti limit 6 invece che 1
-
19 Aprile 2011 alle 13:43 #83622NappaPartecipante
…acc… ci avevo già pensato, ma ne mette sempre 1… non ci vuole qualche loop tipo foreach ()?
-
19 Aprile 2011 alle 13:56 #83623SteveAglAmministratore del forum
bhe se ne estrai uno $hilite è un array… ovviamente…
-
19 Aprile 2011 alle 14:02 #83624SteveAglAmministratore del forum
anzi la query di prima va non più in $wpdb->get_var ma in $wpdb->get_var ma in $wpdb->get_results che torna un oggetto o un altro tipo di array.
http://codex.wordpress.org/Function_Reference/wpdb_Class#SELECT_Generic_Results
-
19 Aprile 2011 alle 14:58 #83625NappaPartecipante
… perdonatemi, ma se…
$hilite = $wpdb->get_var( “SELECT ID FROM $wpdb->posts WHERE post_type = ‘attachment’ ORDER BY RAND() LIMIT 6” );
echo ” . wp_get_attachment_image( $hilite, ‘scroll-thumbnail’ ) . ”;
… faccio
print_r($hilite);
dovrebbe stamparmi in contenuto dell’array, giusto?
mi da solo un numero
-
19 Aprile 2011 alle 15:19 #83626SteveAglAmministratore del forum
ed infatti la mia risposta era in due parti.. rileggi l’ultima…
-
19 Aprile 2011 alle 16:45 #83627NappaPartecipante
mah… ho risolto, anche se penso non nel modo più veloce…
cosଠfunziona e mi restituisce il thumbnail dell’ID random trovato
Grazie ragazzi
$imagesRand = $wpdb->get_results( “SELECT ID FROM $wpdb->posts WHERE post_type = ‘attachment’ ORDER BY RAND() LIMIT 6” );
//print_r($imagesRand); — DEBUD
foreach ($imagesRand as $imageRand) {
$imageScrollID = $imageRand->ID;
$hilite = $wpdb->get_var( “SELECT ID FROM $wpdb->posts WHERE ID = $imageScrollID” );
echo ” . wp_get_attachment_image( $hilite, ‘scroll-thumbnail’ ) . ”;
}
-
19 Aprile 2011 alle 17:32 #83629SteveAglAmministratore del forum
si visto che questo:
$imageScrollID = $imageRand->ID;
$hilite = $wpdb->get_var( “SELECT ID FROM $wpdb->posts WHERE ID = $imageScrollID” );
echo ” . wp_get_attachment_image( $hilite, ‘scroll-thumbnail’ ) . ”;
basta sia cosà¬:
echo ” . wp_get_attachment_image( $imageRand->ID, ‘scroll-thumbnail’ ) . ”;
-
20 Aprile 2011 alle 12:09 #83652NappaPartecipante
MITICI… funziona tutto alla perfezione
anche se il sito e’ in progress, ecco l’indirizzo
http://www.decimamusa.it/associazione/
GRAZIE A TUTTI
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.