Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Created October 20, 2012 19:56
Show Gist options
  • Save ChrisLTD/3924562 to your computer and use it in GitHub Desktop.
Save ChrisLTD/3924562 to your computer and use it in GitHub Desktop.
Drupal 7 image gallery output
// Requires Content Type with image field with multiple images as described here: http://drupal.stackexchange.com/a/5901
// Title is output as caption if there is title text
// Image size is determined by custom image style in Drupal admin named "gallery_thumb"
<?php
$gallery_images = $node->field_gallery_image['und'];
for($i = 0; $i < count($gallery_images); $i++) {
$image = $gallery_images[$i];
$output = '<a href="' . file_create_url($image['uri']) . '">';
$output .= '<img src="' . image_style_url("gallery_thumb", $image['uri']) . '">';
if($image['title'] != ""){
$output .= '<span>' . $image['title'] . '</span>';
}
$output .= '</a>';
echo $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment