如何在drupal中编辑搜索区域

时间:2011-04-04 14:38:25

标签: css drupal templates search

在我的网站www.rchealth.co.uk,我想添加搜索。

我启用了搜索模块,搜索块位于标题中,现在我想自定义搜索外观以便更好看。

我搜索并找到了一些方法,例如http://systemseed.com/blog/how-customise-search-box-drupal-6http://drupal.org/node/154137

我按照步骤操作但仍无法编辑模板。我的drupal版本是6.17

我将此代码粘贴到template.php

function accordlaw_preprocess_search_block_form(&$vars, $hook) {
  // Modify elements of the search form
  unset($vars['form']['search_block_form']['#title']);

  // Set a default value for the search box
  $vars['form']['search_block_form']['#value'] = t('Search RC Health');

  // Add a custom class to the search box
  // Set yourtheme.css > #search-block-form .form-text { color: #888888; }
  $vars['form']['search_block_form']['#attributes'] = array(
     'onblur' => "if (this.value == '') {this.value = '".$vars['form']['search_block_form']['#value']."';} this.style.color = '#000000';",
     'onfocus' => "if (this.value == '".$vars['form']['search_block_form']['#value']."') {this.value = '';} this.style.color = '#000000';"
  );

  // Modify elements of the submit button
  unset($vars['form']['submit']);

  // Change text on the submit button
  //$vars['form']['submit']['#value'] = t('Go!');

  // Change submit button into image button - NOTE: '#src' leading '/' automatically added
  $vars['form']['submit']['image_button'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/search-button.png');

  // Rebuild the rendered version (search form only, rest remains unchanged)
  unset($vars['form']['search_block_form']['#printed']);
  $vars['search']['search_block_form'] = drupal_render($vars['form']['search_block_form']);

  // Rebuild the rendered version (submit button, rest remains unchanged)
  unset($vars['form']['submit']['#printed']);
  $vars['search']['submit'] = drupal_render($vars['form']['submit']);

  // Collect all form elements to print entire form
  $vars['search_form'] = implode($vars['search']);
}

1 个答案:

答案 0 :(得分:2)

你说搜索块在标题中...你的意思是主题搜索?您使用的代码是搜索表单。

当您未以管理员身份登录时,您无法看到搜索表单的最可能原因是您没有使用“搜索”到匿名(可能是经过身份验证的)用户的正确权限。

要在主题标题中更改主题搜索的外观/功能,您也可以随时使用模板文件(search-theme-form.tpl.php)。

从“/ modules / search”复制search-theme-form.tpl.php并将其粘贴到您的主题目录中。进行所需的任何修改,然后在“www.example.com/admin/settings/performance”清除缓存。

有关使用search-theme-form.tpl.php的更多信息:
search-theme-form.tpl.php (Drupal Docs)
How to Theme the Search Form for Drupal 6