How to theme search results drupal 6.x

Drupal 6 comes up with preprocess functions and templates which makes theming job easier. So here is my first post to make your theming job easier with drupal 6.x.

Lets take a scenario of having some text below each result in search result page, could be any kind of ad or some image or any HTMl component.

Step 1. Define a variable in a preprocess function in template.php file.
Step 2. Copy the search-result.tpl.php file from /modules/search directory to your current theme folder.
Step 3. echo the defined variable in the search-result.tpl.php file.
Step 4. Clear the template cache.


Step 1. Define a variable in a preprocess function in template.php file.
Append following code to template.php in current theme.

function mytheme_preprocess_search_result (&$vars) {
 
$vars['my_variable'] = t('I am here');
}


Step 2.  This is self explanatory

Step 3. echo the defined variable in the search-result.tpl.php file.
Append following code at end of search-result.tpl.php
if (!empty($my_variable)) {
    echo $my_variable
;
  }
Step 4. Clear the template cache.

Now you can edit these files and can customize your search result page. :)

Share this post with your friends