When you have a field designed to accept multiple images (e.g. a photo gallery field) there is no way currently to just display the first image. This would be very useful for teasers.

I wrote my own very simple custom module to achieve this. I'm sorry I don't have time to patch media module, but hopefully this code will help someone dealing with the same problem. (this works for both 'media' and 'image' field types)

Comments

Chris Gillis’s picture

Status: Active » Needs review
StatusFileSize
new3.2 KB

Patch Attached

Scott J’s picture

Chris,
Thank you! Do you know how many years people have been asking for just such a formatter for imagefield? I've been doing this with a field.tpl.php file, but it's nice to be able to just turn it on in content type display settings.

Now, if we could just choose the number of images to display...

babycourageous’s picture

This is fantastic.
Would the code for a D6 version be much different?

Scott J’s picture

Rene,
Try ImageField Single for D6.

FrequenceBanane’s picture

no review for this patch ?

steve.m’s picture

The custom module works for me. I'm using it via views with no problems. I turned it into the singleimage module (search and replace 'custom_' to 'singleimage_' and rename the files/directory) and it works fine. Thanks for this!

dave reid’s picture

Status: Needs review » Closed (won't fix)

This feature is out of scope for the Media module. Feel free to create a sandbox project for this or make it a full module.

ressa’s picture

Issue summary: View changes

A work around for drupal 11, without adding extra modules such as Display Suite, is using Views:

  1. Hide the image field in the content type display
  2. Add a View with only the image (check the box for "Display all values in the same row", and set display to "1")
  3. Add a Contextual filter using ID (Content ID from URL)