Hello!

I am baffled on how to customize the search result of Drupal... How can I let the search result view only the title and details of the page without showing the author or the date and number of comments after it...

Thank you very much...

Comments

nimazuk’s picture

hi,
You can add this code to your theme's Template.php file. Just replace the THEME-NAME with your own theme name.

<?php
function THEME-NAME_search_item($item, $type) {
  $output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']) .'</a></dt>';
  $info = array();
  $output .= ' <dd>'. ($item['snippet'] ? '<p>'. $item['snippet'] .'</p>' : '') .'<p class="search-info">'. implode(' - ', $info) .'</p></dd>';
  return $output;
}
?>

Actually this theme function overrides the search result function in search.module.

here is the original code, you can leave some items like date or ...

<?php
function THEME-NAME_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']) {
    $info[] = check_plain($item['type']);
  }
  if ($item['user']) {
    $info[] = $item['user'];
  }
  if ($item['date']) {
    $info[] = format_date($item['date'], 'small');
  }
  if (is_array($item['extra'])) {
    $info = array_merge($info, $item['extra']);
  }
  $output .= ' <dd>'. ($item['snippet'] ? '<p>'. $item['snippet'] .'</p>' : '') .'<p class="search-info">'. implode(' - ', $info) .'</p></dd>';
  return $output;
}
?>

N.Mehrabany
Baruzh web design & programming

Nima

johnrosswvsu’s picture

I'll try these codes this insatan...

John Ross C. / Web Developer
johnross@prometsource.com
Promet Source
1802 W Berteau Ave Suite 209 Chicago, IL 60613

Drupal Web Development