How do I set that up?

Also is it possible to place two fields next to each other, like in views?

Files: 
CommentFileSizeAuthor
#15 productsearchresult3.jpg55.87 KBfehin
#9 productsearchresult.jpg37.98 KBfehin

Comments

swentel’s picture

Status: Active » Closed (fixed)

1) #788548: Limiting output from pictures field?
2) You can place 2 fields next to eachother with css - you can add styles in the 'styles' screen en select the class in the fields overview screen.

fehin’s picture

I tried your Limit multiple field snippet (http://drupal.org/node/700056) and I got this error message:
Fatal error: Cannot redeclare imagecache_for_nd_contrib_field_formatter_info() (previously declared in sites/all/modules/custom_formatters/custom_formatters.module(360) : eval()'d code:9) in /sites/all/modules/custom_formatters/custom_formatters.module(360) : eval()'d code on line 15

fehin’s picture

Status: Closed (fixed) » Active
swentel’s picture

That code snippet is for using in a custom module, not pasting them into the custom formatters as a snippet, you'd only need this bit:

  static $images = array();

  $nid = $element['#node']->nid;

  // Stop after the first one.
  if (isset($images[$nid])) {
    return;
  }

  if (empty($element['#item']['fid'])) {
    return '';
  }
  $images[$nid] = TRUE;

  $item = $element['#item'];

  $alt = isset($item['data']['alt']) ? $item['data']['alt'] : '';
  $title = isset($item['data']['title']) ? $item['data']['title'] : NULL;

  // Not sure, if you have to return here, could be 'echo' too, so choose one or the other.
  return theme('imagecache', 'uc_category', $item['filepath'], $alt, $title);
  //echo theme('imagecache', 'uc_category', $item['filepath'], $alt, $title);
fehin’s picture

I tried your last code in custom formatter and multiple images are still returned.Thanks for the help.

fehin’s picture

About placing fields next to one another, I added two classes
mycol1
mycol2
When I tried to use these classes I got this error message "An illegal choice has been detected. Please contact the site administrator.".

swentel’s picture

swentel’s picture

This works fine when using custom_formatters module - Use the advanced editor, enter filefield as fieldtypes and toggle the 'handle' multiple values' checkbox.

$i = 0;
$output = '';
foreach (element_children($element) as $key) {
  if ($i < 1) {
    $item = $element[$key]['#item'];
    if (empty($item['filepath'])) {
      continue;
    }
    $i++;
    $alt = isset($item['data']['alt']) ? $item['data']['alt'] : '';
    $title = isset($item['data']['title']) ? $item['data']['title'] : NULL;
    $output .= theme('imagecache', 'IMAGECACHE_PRESET', $item['filepath'], $alt, $title);
  }
}
return $output;
fehin’s picture

FileSize
37.98 KB

Thank you for that info.

I was able to fix the issue with multiple images by setting height of the image field and hide the overflow. The issue I'm having now are
1) find a way to truncate the titles
2) remove title paragraph. It leaves too much space between the fields
3) remove the "price" label from ucd_sell_price. Even though the label is set to hidden, it still shows.

Please see my attached image. Thanks. I appreciate your help so far.

fehin’s picture

Just saw your #8 post. I will try that out. Thanks.

fehin’s picture

Yay! The code worked. No need for the css. Thank you very much.
Now I just have to find the solution to my post in #9.

swentel’s picture

Well for #9 1 and 2: The title displays are theming functions from nd, so you can override them with phptemplate in your template.php of your theme - you can remove the paragraph titles there and use a truncate function - http://api.drupal.org/api/function/truncate_utf8/6

// truncate can happen with truncate_utf8
// Not linked.
function phptemplate_nd_title_p_nolink($field) {
  return '

'. check_plain($field['object']->title) .'

'; } // Linked. function phptemplate_nd_title_p_link($field) { return '

'. l($field['object']->title, 'node/'. $field['object']->nid) .'

'; }

For 3 (label price): that's coming from ubercart from the theme_uc_product_price() function which is very complicated. I'm not an ubercart expert, but i'd almost think that there is an option in ubercart itself to remove that label.

fehin’s picture

I tried

 function phptemplate_nd_title_p_link($field) {
return l( truncate_utf8($field['object']->title, 20, TRUE, TRUE),$field['object']->title, 'node/'. $field['object']->nid);
}

and I got "Fatal error: Unsupported operand types in /includes/common.inc on line 1592"

The price label wasn't caused by ubercart but by my theme (acquia prosper). They have two options for displaying price. I chose the other option (ucd_display_price) and it doesn't have that label.

About displaying two fields on the same line. I applied the style but not sure what to do next.

swentel’s picture

You were using a parameter to much:

function phptemplate_nd_title_p_link($field) {
  return l(truncate_utf8($field['object']->title, 20, TRUE, TRUE), 'node/'. $field['object']->nid);
}

As for displaying fields on two lines, those classes/styles should like define a 'float: left' (or something like that) in your CSS - I'm not *that* good in styling, I have themers for that at work :)

fehin’s picture

FileSize
55.87 KB

Thank you very much. It worked. Is there a way to isolate this title setting to only product and product_kit node types'?

I didn't need the style class afterall. Floating .buildmode-3 .node-type-product .field-sale-list-price to left moved the next field (field-ucd-display-price) to the same line. Attached in my end result. I still need to figure out how to make my cck computed field (field-sale-list-price) display two decimal points but that's not this module issue. Thank you very much again for your help.

swentel’s picture

Status: Active » Closed (fixed)

Yep, you can:

function phptemplate_nd_title_p_link($field) {
  $type = $field['object']->type;
  if ($type == 'product') {
    return l(truncate_utf8($field['object']->title, 20, TRUE, TRUE), 'node/'. $field['object']->nid);
  }
  else {
    // Default theming function.
    return '

'. l($field['object']->title, 'node/'. $field['object']->nid) .'

'; } }
fehin’s picture

Thank you.:)

razorback’s picture

Does anyone have a summary of the steps to display a single image on the search page? I'm not clear on where to start. Thanks

BeWhy’s picture

to ask an obvious question, so this is saying that this code depends on also using the custom-formatters module and to put this code in there?

There's no solution in creating a custom field from within ds/nd itself?

Danny_Joris’s picture

I just want to express my appreciation for the code snippet in #8.

Thanks! :)

BeWhy’s picture

just a couple further instructions for #8:

1. edit the 'IMAGECACHE_PRESET' from the code above on the line starting "$output" to correspond to the particular imagecache preset that you want show (othewise you'll get the broken image sign)

2. in the manage fields/build mode interface, click 'change settings' for the image and change the 'feild format' to 'Custom:your_named_field'

ycwjjjj’s picture

Status: Closed (fixed) » Needs review

I follow the instruction from #8 and #21, however, I can't make the first image to be displayed in teaser view for custom_formatter 1.5 beta4. No picture was shown after the setting.
It can work with custom_formatter 1.4.
Can anyone give me some hints?!
Thanks!

Danny_Joris’s picture

Status: Needs review » Closed (fixed)

#22 Can you post your snippet?

Have you entered 'filefield' as fieldtypes and did you toggle the 'handle multiple values' checkbox?

It's also always helpful if you start out with looking into everything that's in the $element array, using <?php print dsm($element); ?> (enable Devel for this)

kclarkson’s picture

@Swentel,

I apologize in advance for my lack of PHP skills so it could be something very simple in my code.

I have looked at your post and further instructions below and followed all steps regarding the Custom formatters module.

1. I used advanced editor mode
2. Selected the Handle multiple values
3. Pasted the code into the php area
4. Went back to the display suite build mode and selected the custom field type.

It looks like where I am messing something up is in the "imagecache preset name". I understand that I am supposed to change image cache preset to the name I am using. Am I supposed to put this somewhere else as well?

$i = 0;
$output = '';
foreach (element_children($element) as $key) {
  if ($i < 1) {
    $item = $element[$key]['#item'];
    if (empty($item['filepath'])) {
      continue;
    }
    $i++;
    $alt = isset($item['data']['alt']) ? $item['data']['alt'] : '';
    $title = isset($item['data']['title']) ? $item['data']['title'] : NULL;
    $output .= theme('imagecache', 'imagecache-node-image', $item['filepath'], $alt, $title);
  }
}
return $output;
fehin’s picture

@kclarkson
Your Field type(s): should be "filefield" and in this line $output .= theme('imagecache', 'imagecache-node-image', $item['filepath'], $alt, $title);, your 'imagecache-node-image' should be the name of the imagecache preset that you want to use, make sure this already exist.

kclarkson’s picture

@fehin

Thanks for the quick response. I did make the field type filefield and I do have a node-image for a imagecache preset. I guess where something is wrong is the naming of my imagecache in the pHP code.

In the imagecache preset listings it is actually named node-image. With that said are you familiar with how the PHP names differ as I have tried numerous variations?

Thanks

a_c_m’s picture

For what its worth, i've just created a module to provide an imagecache preset for this situation : http://drupal.org/project/imagefield_single dev version should be released shortly.

fehin’s picture

@kclarkson
Sorry, I'm just seeng your reply. If your preset name is called "node-image" then that is what you put there, not "imagecache-node-image". See mine below. My image preset name is called "product_list".

>$i = 0;
$output = '';
foreach (element_children($element) as $key) {
  if ($i < 1) {
    $item = $element[$key]['#item'];
    if (empty($item['filepath'])) {
      continue;
    }
    $i++;
    $alt = isset($item['data']['alt']) ? $item['data']['alt'] : '';
    $title = isset($item['data']['title']) ? $item['data']['title'] : NULL;
    $output .= theme('imagecache', 'product_list', $item['filepath'], $alt, $title);
  }
}
return $output;
ball.in.th’s picture

I've found a quick workaround to show only the first value of any cck fields in teasers.

With Node displays contributions module:
Copy sites/all/modules/nd_contrib/nd_cck/nd_cck.tpl.php to your theme directory, if it doesn't already exist.
Without Node displays contributions module (plain CCK module):
Copy sites/all/modules/cck/theme/content-field.tpl.php to your theme directory, if it doesn't already exist.

Then edit the copied file in your theme directory, change from

$count++;

to

$count++; if ($teaser) { break; }

And then flush the theme registry.

TravisCarden’s picture

Title: Show only the first image in teaser and search result » Show only first image from multi-value imagefield (or "group multiple values")
Status: Closed (fixed) » Closed (works as designed)

See ImageField Single module for a drop-in solution. See Display Suite code snippets for custom formatters code.

Marked these issues as duplicates:

Changing title for findability.

fehin’s picture

Anyone else having problem with their code after Custom Formatters module upgrade? I'm looking for a solution. See the issue here #1147156: Code stopped working after upgrade.

aminalid’s picture

Another quick (but not perfect) solution:
- go to admin/build/ds/nd/fields
- create a code field with the following code:

<?php 
$node = node_load($object->nid);
if(isset($node->cck_filed_name[0]['filepath'])) {
print theme('imagecache', 'imagecache_preset', $node->cck_field_name[0]['filepath']);
}
?>

- replace "cck_field_name" and "imagecache_preset" above with the actual names from your setup

recidive’s picture

I just contributed a module for limiting images and other multiple values display in Drupal 7. I think it might be useful posting it here:

http://drupal.org/project/field_multiple_limit

swentel’s picture

Also note, that the Drupal 7 version of Display Suite has this built in now, see http://realize.be/limit-number-fields-display-field-ui-display-suite

recidive’s picture

Sweet, but bad timing.

swentel’s picture

depends, not everyone uses DS and it would stupid to just install DS for limiting their images in the output. So, it's actually a win for everybody again I guess.

Danny_Joris’s picture

This feature makes so much sense. Thanks for adding it! I'll check it out on Wednesday.