By coupet on
After a search query, a results page shows a list of nodes with standard information including title and some content.
Title and Content can be customized in template.php in theme-folder:
function phptemplate_search_item($item, $type)
{
$output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']) .'</a></dt>';
$info = array();
if ($item['type']) {
Don't output the node type
$info[] = $item['type'];
}
if ($item['user']) {
$info[] = $item['user'];
}
if ($item['date']) {
$info[] = format_date($item['date'], 'small');
}
if (is_array($item['extra'])) {
Don't output the extra information about the node (comments, attachments)
$info = array_merge($info, $item['extra']);
}
$output .= ' <dd>'. ($item['snippet'] ? '<p>'. $item['snippet'] . '</p>' : '') . '<p class="search-info">' . implode(' - ', $info) .'</p></dd>';
return $output;
}
How can above code be modified to display specific CCK content type fields and thumbnails?
All comments greatly appreciated.
Darly
Comments
+1
i too interested to know how to search cck nodes in a block...
Try to get variables of cck
Try to get variables of cck fields like this way:
$n = $item['node'];
$v1 = $n->field_name1[0]['view'] ;
$v2 = $n->field_name2[0]['view'];
$v3 = $n->field_name3[0]['view'];
and custom your theme using the variable $output.
Custom Search results - CCK - Nodes
As per astra comments, final code to display thumbnail in search result:
Assume CCK field name = 'image'.
----
Darly
cant seem to display just a text field
hello
i modified the above code to try to output the contents of a description field..(i only want this under the title)
but.. i cant seem to get it to work. everyhing is the same as above, except i uncommented/changed:
// $img = $n->field_image[0]['view']; to field_description (my field)
and then made $img=n->field_descriptiom[0]['view']
nothing seems to be outputing....
so my question is how to return title + the contents of a particular field.
thanks!!!
maybe you have mistyped
$img=n->field_description[0]['view']
no mistype except in post
thanks for the response!
maybe you can help me clear this up in one swoop...
for some reason, ALL my CCK fields are showing up under the title in search results...how can i just choose the ones i want to show, (like the description field, etc)
again, thanks so much!
theme your content type
i get values from my cck node fields in this manner
print content_format('field_blah', $field_blah[0]);it works perfectly, but then this is for the template so i don't suppose it will help much.
should be
$img=$n->field_description[0]['view']