Show one image on a node teaser

Hook_process_field can be used inside template.php to render only one image on a multiple image field.


/**
 * Implements hook_process_field().
 */
function MYMODULE_process_field(&$vars) {

  switch($vars['element']['#view_mode']) {
    // Only on node teaser.
    case 'node_teaser':
      switch($vars['element']['#field_type']) {
        // Only on image fields.
        case 'image':
          // Only render the first image of a multiple image field.
          $vars['items'] = array(reset($vars['items']));        
          break;
      }
      break;
  }
  
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.