Le script qui suit permet d’obtenir une liste d’images et leur affichage sous forme de galerie lightbox.
Pour l’utiliser on l’associe à :
– un plugin d’insertion de PHP via l’éditeur comme « Shortcode Exec PHP »
– le plugin « Lightbox plus »
– le système webservice de Piwigo ( votre_piwigo/tools/ws.htm ) pour obtenir les arguments à passer à la fonction
Le script :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
extract(shortcode_atts(array('arg' => 'default'), $atts)); //print_r($atts);//pour voir /*si on envoie directement une url avec la partie query comme variable à file_get_contents() il y a une réécriture partielle (!) et la fonction plante (bug du plugin shortcode Exec PHP ?) du coup on passe les éléments essentiels en arguments : - galurl -> url de la galerie moins "http://" - cattag -> peut être "tag" ou "categories" - idname -> peut être sois l'id du tag ou de la categorie, ou le nom du tag */ $query = "?format=php&method=pwg."; if($atts[cattag]=="cat"){ $query = $query."categories.getImages&cat_id=".$atts[idname]; }else{ if(!is_numeric($atts[idname])){$idname = "_name=".$atts[idname];}else{$idname = "_id=".$atts[idname];}; $query = $query."tags.getImages&tag".$idname; }; $response = $atts[galurl]."/ws.php".$query; $response2 = file_get_contents($response); $thumbc = unserialize($response2); if ($thumbc["stat"] == 'ok') { for($i=0;$i<sizeof($thumbc["result"]["images"]["_content"]);$i++){ $picture = $thumbc["result"]["images"]["_content"][$i]; //echo '<a title="'.$picture['file'].'" href="' . $picture['high_url'] . '" rel="lightbox[\''.$atts[galurl].$atts[cattag].$atts[idname].'\']" class="box marg5" style="display:inline-block;text-align:center;vertical-align:middle;width:128px;height:128px;line-height:128px;"><img src="' . $picture['tn_url'] . '" alt="'.$picture['file'].'" /> echo '<a title="'.$picture['file'].'" href="' . $picture['high_url'] . '" rel="lightbox['.$atts[cattag].$atts[idname].']" class="box marg5" style="display:inline-block;text-align:center;vertical-align:middle;width:128px;height:128px;line-height:128px;"><img src="' . $picture['tn_url'] . '" alt="'.$picture['file'].'" /> </a>'; } } |
Exemples :
images correspondant au tag « panoramique » et shortcode :
[ piwigo_galerie galurl= »http://sebguerin.free.fr/piwigo » cattag= »tag » idname= »panoramique » ]
http://sebguerin.free.fr/piwigows.php?format=php&method=pwg.tags.getImages&tag_name=panoramique
images correspondant au tag d’ID 32 et shortcode :
[ piwigo_galerie galurl= »http://sebguerin.free.fr/piwigo » cattag= »tag » idname= »32″ ]
http://sebguerin.free.fr/piwigows.php?format=php&method=pwg.tags.getImages&tag_id=32
images correspondant à la categorie d’ID 161 et shortcode :
[ piwigo_galerie galurl= »http://sebguerin.free.fr/piwigo » cattag= »cat » idname= »161″ ]
http://sebguerin.free.fr/piwigows.php?format=php&method=pwg.categories.getImages&cat_id=161