theme_search_item

Versions
4.6 – 5
theme_search_item($item, $type)

Format a single result entry of a search query.

Modules may implement hook_search_item() in order to override this default function to display search results.

Parameters

$item A single search result as returned by hook_search(). The result should be an array with keys "link", "title", "type", "user", "date", and "snippet". Optionally, "extra" can be an array of extra info to show along with the result.

$type The type of item found, such as "user" or "node".

Related topics

Code

modules/search.module, line 829

<?php
function theme_search_item($item, $type) {
  if (module_hook($type, 'search_item')) {
    $output = module_invoke($type, 'search_item', $item);
  }
  else {
    $output = ' <dt class="title"><a href="'. check_url($item['link']) .'">'. check_plain($item['title']) .'</a></dt>';
    $info = array();
    if ($item['type']) {
      $info[] = $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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.