Discussions

One image only in teaser display

hello.
I've set up a catalog, and added a few products, I've installed image zoom to use of the node display, I don't want to use image zoom for the teaser display, so I set it to just use the normal medium sized image, only it shows both of the images that were uploaded to the product line item on the taxonomy page using the teaser.

is there anyway to only show one image on the teaser display?

Posted: Feb 21, 2012

Comments

ShaunP1989 on February 21, 2012

The way I managed it isn't an ideal solution, but for each product create an extra field called 'teaser image' and then upload the image you want to be displayed in the teaser, and then just show that image in the teaser view and disable it in the main view.

Shaun

openfeat on February 22, 2012

Cheers Shaun,

I found a module that lets you select how many images to show but it only worked on the display content types, and not product content types.

atm, I think my best option is to do what you suggested.

Thanks or the help.

leanderl on September 17, 2013

Had to solve this today and this is one way to do it through the themes template.php

function MYTHEME_preprocess_node(&$variables)

if(isset($variables['content']['product:field_product_image']) && !empty($variables['content']['product:field_product_image'])) {
if ($variables['content']['product:field_product_image']['#view_mode'] == 'node_teaser') {
$count_images = count($variables['content']['product:field_product_image']['#items']);
if ($count_images > 1) {
$i = 0;
while ( $i < $count_images) {
unset($variables['content']['product:field_product_image'][$i+1]);
$i ++;
}
}
}
}
}

pari pari on June 12, 2015

Try this code in custom module

<?php
/**
 * Implements hook_entity_view().
 */
function custom_commerce_entity_view($entity, $type, $view_mode, $langcode) {
 
//limit images on product teaser block to only first one
 
if (in_array($view_mode, array('teaser', 'search_result'))) {
    if(isset(
$entity->content['product:field_images'])) {
     
$entity->content['product:field_images']['#items'] = array_slice($entity->content['product:field_images']['#items'], 0, 1);
    }
  }
}
?>