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?
Comments
The way I managed it isn't an
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
Cheers Shaun, I found a
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.
You can write you own teaser
You can write you own teaser logic in you node template file. Use the $teaser value
Only one image through template.php
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 ++;
}
}
}
}
}
Best approach
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);
}
}
}
?>