Drupal 7 gallery teaser
I've created a simple gallery in Drupal using a custom content type. It's really just an article with an image field that can have an unlimited number of items. I've created a custom temp开发者_如何学Golate for this content type (node--gallery.tpl.php) and for the full page I'm satisfied with the look and feel.
The one thing I'm stuck on is displaying only the first few images in the teaser. I want to display just the first row of images in the teaser (that first 3 images). In the template file, $content['field_images']
contains all the images for the gallery but print render($content['field_images']
outputs all the images (as I would expect).
So, how do I get Drupal to just output the first three items from $content['field_images']
? An improvement I would be interested in is how would I get Drupal to output 3 random images although if I know how to cut down the number of images rendered I'm confident I can work that one out myself.
Instead of doing a var_dump or iterating over the array why not install the devel module and make use of its dpm() function which gives a nice output.
In your template, find the appropriate array structure that has the image file names in it. If you can't find it in $content
, look at the var_dump output of $node
. Write a for
loop to iterate over the first three items and for each of these items call either theme_image() or if you have image styles you want to use, theme_image_style(). Pass in the appropriate configuration array to either using the file name you retrieved from the array.
精彩评论