I wish to limit number of images in teaser to 4 along with using imagecache module.
Here is my teaser code:

<div class="field field-type-image field-field-pictures-scoop">

  <div class="field-items">
    <?php foreach ((array)$node->field_pictures__scoop as $item) { ?>
      <div class="field-item"><?php print $item['view'] ?></div>
    <?php } ?>
<?php
print theme('imagecache', $profilepic, $image['filepath'])
?>
  </div>
</div>

Thank you for help!!!

Comments

jrglasgow’s picture

This is the way I would do it. Create a counter, and only dispay the first 4 images.

<div class="field field-type-image field-field-pictures-scoop">

  <div class="field-items">
    <?php 
      $count = 0; // create a counter
      foreach ((array)$node->field_pictures__scoop as $item) { 
        $count++; // increment the counter, if this is the first one, this will get set to 1
        if ($count <= 4) { //check to see how many we already have
          print '<div class="field-item">'. $item['view'] .'</div>'; // print the image
        }
      } 
      print theme('imagecache', $profilepic, $image['filepath'])
    ?>
  </div>
</div>

This is pseudo code, it has not been tested.

Richard_’s picture

Thank you jrglasgow!

Your help is very appreciated and your code work perfectly :)

Regards,
Richard

jrglasgow’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.