My view is displaying nodes of a CCK content type. This content type contains several CCK fields, some of which are repeated to allow multiple values. Specifically, I have multiple header images on this CCK content type. In my view, I wish for only the first image to appear, but what's happening instead is that not only are all images showing for that node, but in fact, the node is repeating itself for each image! (one header image apiece, other info repeated)

Is it normal? How can I change the behavior so that I only get the first image? I am already using a custom theme which is as simple as:

<div class="shell">
    <div class="view-label view-data-title title">
      <?php print $title ?>
    </div>
    <div class="view-field view-data-field-short-description-value">
      <?php print $field_header_image_fid?>
      <div class="desc">
        <?php print $field_quickfacts_value?>
      </div>
    </div>
</div>

Comments

texas-bronius’s picture

So I think a way I can work around this is by checking against the previously displayed node id. If it's the same, then proceed without any output from the template. In the Drupal way, where should I store this persistent php variable? ($bjm_prevnid in my code below, which doesn't persist from one run to the next)

 <?php
 // this View repeats node output for each header image.. not sure why, but I work around 
 // it with a check to see if I'm still on the same node or not
 
 // store current node id:
 if (!isset($bjm_prevnid)) {
     $bjm_prevnid = -1;
 }
 if ($node->nid != $bjm_prevnid) {
 ?>
<div class="shell">
    <div class="view-label view-data-title title">
      <?php print $title ?> <?php print $count ?>
    </div>
    <div class="view-field view-data-field-short-description-value">
      <?php print $field_header_image_fid?>
      <div class="desc">
        <?php print $field_quickfacts_value?>
      </div>
    </div>
</div>
<?php
 }
 $bjm_prevnid = $node->nid;
?>

--
http://drupaltees.com
80s themed Drupal T-Shirts

texas-bronius’s picture

So I prepended my code snippet listed above with global $bjm_prevnid;. Is that the best way? It works for me.. One side effect is that the Views variable $count is skipping around as can be expected, and I suspect that $stripe is affected as well, which can be expected.
--
..happiness is point and click..

--
http://drupaltees.com
80s themed Drupal T-Shirts

texas-bronius’s picture

ok, I thought I was golden with my fix above ... until I tried in IE. Naturally, IE still renders even the blank LI's whereas Firefox easily collapses them. So I am left with a nice box of content for each desired node, but then I have literally empty LI's in between, one for each cck multi-value header image which I wished not to display.

Ideas??!

--
http://drupaltees.com
80s themed Drupal T-Shirts

bones’s picture

Have you tried adding the filter "Node: Distinct". This should do exactly what you want.
I am trying to have it list all values of a 'multi-value-field' but under one 'title', this is proving more difficult. Any ideas?

texas-bronius’s picture

bones- Yes sir, that certainly did the trick! Thank you so much!
You can check it out here:
http://www.brazoscountyexpo.com
the list of facilities on this and on the facilities page both use that same view (and same filter ;) )
I will tinker a bit to solve your problem. In SQL it would be a grouping thing...

btw: I recall from my trial this afternoon that Views in Drupal 5.0 gives you the capability to dictate how to handle repeat-occurrence multiple-value fields with a simple dropdown just like "handler".

--
..happiness is point and click..

--
http://drupaltees.com
80s themed Drupal T-Shirts

bones’s picture

I have found that the cvs version of views has it sorted. :-) it has a dropdown like you say even for 4.7!

texas-bronius’s picture

Here's a bit of a stretch of a related question-- until v5 cck "filefield" is out, I am stuck trying to use file attachments for files on a node. With a single file attachment, I can theme the heck of it without problem. If I have multiple files, it seems the only way I can get them all to display without repeating the node (and to show more than the first attachment when using Distinct) is to use the views-built $all_files. This gives a no-frills pipe- (|)- separated list of links to files attached to a node, but I can't figure out where to theme that "collection."

Specifically, I want to get to the files' description attributes ($file->description, I think) to link them instead of the actual filename. I can't see $files as a collection on the node here.

ideas?

--
http://drupaltees.com
80s themed Drupal T-Shirts

FlymastaFlex’s picture

I also tried 2 days to work around this problem, till i discovered to let views
a) not show multiple fields as grouped
b) filter it with node:distinct.