I've added an image field in a content type, and set the 'Field Settings' -> 'number of values' to unlimited, which means users can upload unlimited images for this field.

Then I build a view for this content type and expose the image filed to the view. What I'd like is to expose only image in teaser view, and all images in the full view.

I use a template preprocess function

function MYTHEME_process_field(&$vars) {
  $element = $vars['element'];
  // Field type image
  if ($element['#field_type'] == 'image') {
    // Reduce number of images in teaser view mode to single image
    if ($element['#view_mode'] == 'teaser') {
      // something might be wrong here
      $item = reset($vars['items']);      // not working
      $vars['items'] = array($item);      // not working

In debugging this function, this 2 lines

  $item = reset($vars['items']);      
  $vars['items'] = array($item); 

It doesn't seem to work because the image field in the content type can have multiple images.

1 Answer 1


I just tested that exact code in Drupal 7 and it's working perfectly! The full view displays two or more images and a view of teasers just shows one image per node.

HOWEVER, I did notice the following: if you're just in the process of building a view the Preview below the view does not display the final output correctly. The Preview in the view of teasers shows multiple images per teaser, but if you just go ahead and hit 'save' and then test your view (by going to its link if it's a page), you'll see that it actually displays correctly.

Does that end up working for you?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.