thierry-b
12/17/2013 - 9:32 AM

Images block: gives the images on positions >1 another image-style.

Images block: gives the images on positions >1 another image-style.

<?php

/**
 * Implements template_process_field().
 */
function template_process_field(&$variables, $hook) {
  if($variables['element']['#field_name'] == 'field_images' &&
     $variables['element']['#view_mode'] == 'full') {

    // Add a specific template file for the imagesblock
    $variables['theme_hook_suggestions'][] = 'field__field_images__imagesblock';
    if (isset($variables['element']['#object']->type)) {
      $variables['theme_hook_suggestions'][] = 'field__field_images__' . $variables['element']['#object']->type . '__imagesblock';
    }

    // Don't link to the original image but link to a "maximum" image style.
    // This makes it less heavy if the originally uploaded images are really big
    foreach ($variables['items'] as $key => $img) {
      $variables['items'][$key]['#path']['path'] = image_style_url('maximum', $img['#item']['uri']);
    }
  }
}
<?php
/**
 * @file
 *  HTML structure for image block
 */
?>

<ul class="imgs-block">
<?php foreach ($items as $key => $item): ?>
  <?php if($key !== 0): ?>
    <?php $item['#image_style'] = 'imgs-block-small'; ?>
  <?php endif; ?>
  <li class="colorbox">
  <?php print render($item); ?>
  </li>
<?php endforeach; ?>
</ul>