13 replies [Last post]
BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
Was this information Helpful?

I searched for a solution to this and found a lot of mixed topics lacking direct content.

I know it has been suggested, but I would like to start this thread as a more organized topic.

We need to have the ability to show a small thumbnail when viewing site-wide search results. The product image would only appear for search results of actual products (logically), and that would be ok for me.

Let's get some info posted here and let's get this done!!

thill's picture
Offline
Joined: 01/25/2008
Juice: 815
Re: Official Show Product Images when performing a site-wide sea

How we did it at http://www.illusionsystems.com was to to insert this in the template.php file in your theme:

function phptemplate_search_item($item, $type) {
  $output = node_view(node_load($item['node']->nid), TRUE);
  return $output;
}

WE also used the search restrict module to restrict search results to products only, this might not be the best in all situations but what the client wanted in this case.

BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
thill wrote:How we did it at
thill wrote:

How we did it at http://www.illusionsystems.com was to to insert this in the template.php file in your theme...

Hmmmm this is pretty nice, as it does work, but I would rather only see the product Name and only 1 image (see this thread)

I might try to hack the results with CSS to hide the fields I'm not interested in, but definitely this is a valid solution!

Thank you very much!
BigMike

atlithor's picture
Offline
Joined: 03/09/2009
Juice: 9
Re: Re: Official Show Product Images when performing a site-wide

How do you put this code to use? I've inserted it in template.php but don't i need to call it up in the search-result.tpl.php?
I am trying to get images from ubercart to show up in my search results.

BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
atlithor wrote:How do you
atlithor wrote:

How do you put this code to use? I've inserted it in template.php but don't i need to call it up in the search-result.tpl.php?
I am trying to get images from ubercart to show up in my search results.

I am using Drupal 5.x + UC 1.x and all I did was add it to the very end of my template.php. Nothing else is required.

Search results return full product nodes including description, price, attributes, and cart links which is rather messy. I am working on figuring out how to only display a thumbnail image to the left of each search result, if it is a product.

BigMike

BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
I tried playing with...  

I tried playing with...

  $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);

  if ($type == 'product') {

and also

    $output .= theme('imagecache', 'uc_thumbnail', $catalog->image['filepath'], $catalog->name, $catalog->name, array('class' => 'category'));

But I have no clue what I am doing so I gave up Smiling lol

markcheng's picture
Offline
Joined: 02/24/2009
Juice: 13
for the n00bs...

replace "phptemplate" in the function name with the name of your function. For example i am using the garland theme, so i renamed this to "garland_search_item"

hope this helps some ppl. mc

thill wrote:

How we did it at http://www.illusionsystems.com was to to insert this in the template.php file in your theme:

function phptemplate_search_item($item, $type) {
  $output = node_view(node_load($item['node']->nid), TRUE);
  return $output;
}

WE also used the search restrict module to restrict search results to products only, this might not be the best in all situations but what the client wanted in this case.

BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
markcheng wrote:replace
markcheng wrote:

replace "phptemplate" in the function name with the name of your function. For example i am using the garland theme, so i renamed this to "garland_search_item"

hope this helps some ppl. mc

thill wrote:

How we did it at http://www.illusionsystems.com was to to insert this in the template.php file in your theme:

function phptemplate_search_item($item, $type) {
  $output = node_view(node_load($item['node']->nid), TRUE);
  return $output;
}

WE also used the search restrict module to restrict search results to products only, this might not be the best in all situations but what the client wanted in this case.

markcheng,

Will this only return images for products only?

ferrangil's picture
Offline
Joined: 02/27/2009
Juice: 62
Re: markcheng wrote:replace

I just added that function to my template.php but nothing happens. Search results looks like always (after flushing all caches).

I also copied the search-result.tpl.php file into my theme, but I think I need the get the nid to do a node_load and then show the image. Isn't that an option?
I'll try to get the nid from the URL and then just print what I need...

totsubo's picture
Offline
Joined: 11/12/2009
Juice: 163
Re: Re: markcheng wrote:replace

Same here. I added the following to themes/garland/template.php but no change in my search results:

function garland_search_item($item, $type) {
$output = node_view(node_load($item['node']->nid), TRUE);
return $output;
}

I also tried to name the function hook_search_item() but that did not help either.

Jc

BigMike's picture
Offline
Joined: 10/20/2008
Juice: 1057
Re: Re: Re: markcheng wrote:replace

So has anyone figured this out yet? Smiling

totsubo's picture
Offline
Joined: 11/12/2009
Juice: 163
Re: Re: Re: Re: markcheng wrote:replace

Mike, any luck with this? I've tried a few things myself but still nothing ...

NecroHill's picture
Offline
Joined: 08/12/2008
Juice: 107
Re: Re: Re: Re: Re: markcheng wrote:replace

this outputs teasers with pager in search results, but I don't know how to restrict output to particular fields.

<?php
function phptemplate_search_results($results, $type) {
    foreach (
$results as $result) {
       
$output .= node_view($result['node'], TRUE);
    }
   
$output .= theme('pager', NULL, 10, 0);
    return
$output;
}
?>

any ideas?

j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
Re: Re: Re: Re: Re: Re: markcheng wrote:replace

A very simple approach I just used and which I just posted in the how-to's which can be found
at http://www.ubercart.org/forum/tutorials/15568/i_got_pictures_my_search_r...

It was done by simply adding one line of code and overriding the default file.

add this to your search-result.tpl.php file and put the new copy in your theme folder...

<a href="<?php print $url; ?>"><img src="/sites/default/files/imagecache/product_list/<?php print $result['node']->field_image_cache[0]['filepath']; ?>"/></a>><br>

a bit more of an explanation is at my other post, but the above is all you need for a basic image in the search.

the sites i'm always breaking.... www.sew-la-fabric.com
http://lostpetsla.com (though i hope i never break this one too bad)