/ Published in: PHP
I pieced together this code when I had to do this for a client:
- show the first image attached to a post (based on sort order in gallery tab) in medium size
- put all the other images attached to the post into an imageset so that when you click on the preview image you will see a greybox-gallery to click through with the full size images.
- show the first image attached to a post (based on sort order in gallery tab) in medium size
- put all the other images attached to the post into an imageset so that when you click on the preview image you will see a greybox-gallery to click through with the full size images.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!--Automatic Greybox--> <?php //Die zum Post gehoerenden Bilder ins Array $images schreiben //Put images from post in to array $images. Order by menu order defined in post gallery $images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ); //Pruefen, ob dem Beitrag Bilder angehaengt wurden. //check if there are any images attached to the post { //Den Zaehler auf 0 setzen //set counter to 0 $count=0; //Alle Bilder im Array $images nacheinander durchlaufen //go through all images in array $images foreach( $images as $image ) { $imageID = $image->ID; //fuer jedes Bild im Array die URL von sowohl der Mittleren, als auch der grossen Groesse ermitteln. //get medium and large image url for image $medImageSrc = wp_get_attachment_image_src($imageID, $size='medium', $icon = false); $largeImageSrc = wp_get_attachment_image_src($imageID, $size='large', $icon = false); //Wenn es sich um das erste Bild im Array handelt... //If it's the first image in the array if ($count==0) { //Den Greybox-Code mit einem Vorschaubild ausgeben //output Greybox Code with medium size preview echo"<a href='$largeImageSrc[0]' rel='shadowbox[Bilder]'><img src='$medImageSrc[0]' border='0'></a>"; } //alle Bilder ,die nach dem erstern Bild kommen //this is for all the images that come after the first one else { //unsichtbare Greybox-Verknuepfung darstellen. //create invisible Greybox-Links without preview image echo"<a href='$largeImageSrc[0]' rel='shadowbox[Bilder]'></a>"; } //Zaehler erhoehen. //increase counter $count++; } //foreach } ?> <!--ENDE Automatic Greybox -->