Imagefield w/multiple values via VIEWS: How to display all except first image?

joeboris - May 18, 2009 - 17:23

Hi all!

I have two views with Node-ID arguments.

The first view shows one large image from the imagefield-field.
The second view shows all the images from the same imagefield-field.

I'd like the second view to show all the images except for the first one, which I'm already displaying in the first view.

Is this possible? I've tried with offset=1, but it only seems to work when I'm showing two instances of the same view (strangely).

Thanks,
joeboris

_

WorldFallz - May 18, 2009 - 17:43

I did this by adding an argument to the second view that returns the nid of the item in the first view and checking 'Exclude the argument' in the options for that argument.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

-

joeboris - May 19, 2009 - 08:27

Hi WorldFallz,

and thanks for your swift reply!

I couldn't figure out which argument to add... or did you mean argument handling code?

It may have been unclear in my initial post, but all the images belong to the same node, via an imagefield field with multiple values.

Thanks a lot for your help!
joeboris

_

WorldFallz - May 19, 2009 - 12:09

Sorry I should have been clearer. I found a previous comment where I described this: http://drupal.org/node/377094#comment-1268308

See if that makes more sense.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Hi WF, (I somehow missed your

joeboris - May 25, 2009 - 10:06

Hi WF,

(I somehow missed your reply; it didn't appear in my recent posts list... Thanks for your tip, though I haven't had a chance to look at it properly yet. However, it looks like it applies to offsetting a node, where my trouble has been offsetting one of many values in the same node.. apologies if I'm wrong, though :) )

In the meantime I found another fix for this. I'll include it here so people looking for the same can use it.

I put this code in my template.php (without the php tags, of course)

<?php
function MyThemeName_content_view_multiple_field($items, $field, $values) {
 
$output = '';
 
$i = 0;
  foreach (
$items as $item) {
    if (!empty(
$item) || $item == '0') {
      if (
$i) {
       
$output .= '<div class="shown">'. $item .'</div>';
      } else {
       
$output .= '<div class="hidden">'. $item .'</div>';
       
$i++;
      }
    }
  }
  return
$output;
}
?>

Since the views I use are embedded in a node-template.tpl.php, i then include some css-code such as

.view-list-myview .hidden { display: none; }

This removes the first of the multiple field entries. I guess this could be used for all types of fields, not only images... It's important to specify that this only applies to that specific view, or all first items of multiple values will be removed.

The code has been cannibalized from this issue: http://drupal.org/node/372996

 
 

Drupal is a registered trademark of Dries Buytaert.