如何在预告模式下显示一个图像,而在完整内容下显示多个图像?

Mes*_*yCS 7 drupal drupal-7

我正在使用Drupal 7.2构建一个站点,并使用几个有用的模块(Views,Display Suite和20多个).
我在内容类型(文章)中添加了一个图像字段,并将"字段设置" - >"数值"设置为5,这意味着用户可以为此字段上传5个图像.
在"全内容"视图模式下,我想显示所有图像,但如何在"预告片"模式下仅显示一个图像?有没有模块可以做到这一点?

bjo*_*rnf 9

我通过为这个字段类型添加一个新模板解决了这个问题,比如field-field_image.tpl.php在我的例子中使用以下代码:

// Reduce image array to single image in teaser view mode
if ($element['#view_mode'] == 'teaser') {
  $items = array(reset($items));
}

print render($items);
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.

编辑:这是(可能)正确的方法:

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') {
      $item = reset($vars['items']);
      $vars['items'] = array($item);
    }

  }

}
Run Code Online (Sandbox Code Playgroud)