Closed (outdated)
Project:
Custom Search
Version:
6.x-1.13
Component:
User interface
Priority:
Major
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Apr 2014 at 20:10 UTC
Updated:
26 Oct 2025 at 21:56 UTC
Jump to comment: Most recent
Comments
Comment #1
gauravkhambhala commentedFollowing instruction are for Drupal 7.
Copy YOUR_DRUPAL/modules/search/search-result.tpl.php file to your theme. Add following code to the before printing title in the template. Make sure you replace "field_main_image" with your field's machine name.
Hope this helps.
Comment #2
drupalfan81 commentedThanks for posting this! Actually after I had posted this, I continued my search and came across a few ways of doing this and ended up customizing the template, but slightly different than the way you mentioned above. I'm not sure what the $output variable is, maybe thats a D7 thing. The below is what I did for D6. But just to share what I learned I will explain below what I did. I copied the search-result.tpl.php template file from drupal core as mentioned above and copied it into my themes folder.
In this file were basically a few variables that were being printed to the screen. $info, $snippet, $url, and $title. Basically I used the default
<dt>and<dd>tags to format the output on the screen and then added my CCK fields as needed. The way I did this was as follows:Basically I wanted to output a portion of the "about" section of each node. I have a cck field called field_about where my users write the main summary of that node (or in my site's case, a user review/listing). So to output this about section I used this code:
Basically I only wanted to output at most 250 characters, so I used the php substr and I also stripped the tags to make sure I wouldn't have broken HTML code upon output.
Then since I figured that out, I thought it would be cool to output the country assigned to that listing, which is actually a content taxonomy term. So it's a bit different to output that, as just printing the value would give a number and not the term. To do this, I did:
That solved that problem.
I also use the fivestar widget, so I wanted to display the widget with each node (listing). So I used this:
I also wanted to output a thumbnail of the "featured photo" of each node (listing) which I had as a image field called featured_photo. To do this, I did this:
I was able to use imagecache to properly resize the image on the screen to reduce filesize.
So basically I threw all those in and used some html css to format the look and feel. I absolutely love my search result page now. LOOKS SO MUCH better than the default drupal search results and offers so much more info to my users. I HIGHLY recommend customizing this template file and really get control over your results page. I should have done this a long time ago.
Hope others stumble upon this page and find it helpful. Any feedback or recommendations would be appreciated!
Comment #3
gauravkhambhala commentedGlad that you got it working. I know this issue is posted for Drupal 6 version but still those who are looking for D7, the appraoch remains the same. I would recommend using field_view_field to load fields instead of field_featured_photo[0]['filepath'].
Refer http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way for more explaination.
Comment #4
loon commentedD6 reached its EOL, and there is no active release for D6 for this module anymore.
Development or support is not planned for D6. All D6-related issues are marked as outdated in a bunch.