show only first image in grid view

Contrib type: 
Code/CSS Snippet
Status: 
Complete and working
Latest version: 
1.0

Downloads


Compatibility: 
Ubercart 1.x

In creating my own custom catalog view I wanted to show only the first image from the CCK imagefield for each product.

I was having difficulty and after some time searching through posts on drupal.org and elsewhere i found a number of posts indicating others were/are looking for a solution.

I have come up with one!

If 'do not group multiple values' is selected as the handler for the imagecache field, the multiple images show as as distinct views results (in essence, the same as distinct nodes). As such, when node:distinct is selected as a filter, it filters out all but the first imagefield result - i>success!

Please note you must have 'do not group multiple values' for this to work

Here is the views export

Note: this is based on a taxonomy 'catalog:illustrations' with a custom imagecache preset to suit to display 'illustration_thumbs'.

  $view = new stdClass();
  $view->name = 'grid_view';
  $view->description = 'illustrations grid view';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'My illustrations';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'bonus_grid';
  $view->url = 'test';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '10';
  $view->sort = array (
  );
  $view->argument = array (
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array (
      'tablename' => 'node_data_field_image_cache',
      'field' => 'field_image_cache_fid',
      'label' => '',
      'handler' => 'content_views_field_handler_ungroup',
      'options' => 'thickbox][illustration_thumbs',
    ),
    array (
      'tablename' => 'uc_products',
      'field' => 'addtocartlink',
      'label' => '',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'term_node',
      'field' => 'tid',
      'operator' => 'AND',
      'options' => '',
      'value' => array (
  0 => '1',
),
    ),
    array (
      'tablename' => 'node',
      'field' => 'distinct',
      'operator' => '=',
      'options' => '',
      'value' => array (
  0 => 'distinct',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, node_data_field_image_cache, uc_products, term_node);
  $views[$view->name] = $view;
kasperjames's picture
Offline
Joined: 11/17/2007
Juice: 52
this might sound dumb,...

but whare do i put this?

ksprjms