0

I use below code for printing out images in search results. I get double print outs on the ALT tags. If I disable ALT tags all displays just fine.

<a href="<?php print $url; ?>" class="search-result-img-wrapper">
    <?php
      print theme_image_style(array(
        'style_name' => 'thumbnail',
        'path' => $result['node']->field_image['und'][0]['uri'],
        'alt' => $title,
        'attributes' => array('class' => 'search-result-img'),
      ));
    ?>
  </a>
  <a href="<?php print $url; ?>" class="search-result-img-wrapper">
    <?php
      print theme_image_style(array(
        'style_name' => 'thumbnail',
        'path' => $result['node']->field_product_image['und'][0]['uri'],
        'alt' => $title,
        'attributes' => array('class' => 'search-result-img'),
      ));
    ?>
  </a>

If I add fields like below, I get only the print out of one of the fields and not both.

<a href="<?php print $url; ?>" class="search-result-img-wrapper">
    <?php
      print theme_image_style(array(
        'style_name' => 'thumbnail',
        'path' => $result['node']->field_product_image['und'][0]['uri'],
        'path' => $result['node']->field_image['und'][0]['uri'],
        'alt' => $title,
        'attributes' => array('class' => 'search-result-img'),
      ));
    ?>
  </a>

What am I missing? Thanks much for your input.

1 Answer 1

1

I don't think this will necessarily fix your problem, but you're calling the theme_image_style incorrectly, it should be:

theme('image_style', array(
  'style_name' => 'thumbnail',
  'path' => $result['node']->field_image['und'][0]['uri'],
  'alt' => $title,
  'title' => $title,
  'attributes' => array('class' => 'search-result-img'),
));

Your second example is wrong, you can't call path twice.

4
  • can 2 different fields be put in a path?
    – Thomas
    Commented Apr 14, 2015 at 14:14
  • No you will need to call theme('image_style', ...) twice, what does $title contain? Is it plain text or HTML? Surely, it should be $result['node']->title Commented Apr 14, 2015 at 14:15
  • thank you for your responses and input. $title contains html (ALT tag output).
    – Thomas
    Commented Apr 14, 2015 at 14:36
  • If it contains HTML you will need to strip that off as plain text is expected Commented Apr 14, 2015 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.