如何在drupal中编辑搜索区域

发布于 2024-10-29 05:24:47 字数 2148 浏览 2 评论 0原文

在我的网站 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']);
}

In my site www.rchealth.co.uk, I want to add the search.

I have enabled the search module and the search block is in the header, now I want to customize the search look and feel to look better.

I have searched and found some methods like http://systemseed.com/blog/how-customise-search-box-drupal-6 and http://drupal.org/node/154137

I followed the steps but I am still unable to edit the template. My drupal version is 6.17

i pasted this code in 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']);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你在看孤独的风景 2024-11-05 05:24:47

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

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

要更改主题标题中主题搜索的外观/感觉/功能,您始终可以使用模板文件(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 文档)
如何为 Drupal 6 设置搜索表单主题

You say the search block is in the header... do you mean the theme search? The code you are using is for the block search form.

The most likely reason that you can't see the search form when not logged in as administrator is that you have not given the correct permissions to use 'search' to anonymous (and possibly authenticated) users.

To change the look/feel/functionality of the theme search in the header of your theme, you can always use a template file (search-theme-form.tpl.php) as well.

Copy search-theme-form.tpl.php from "/modules/search" and paste it into your theme directory. Make any edits you want, then clear your cache at "www.example.com/admin/settings/performance".

More information on using search-theme-form.tpl.php:
search-theme-form.tpl.php (Drupal Docs)
How to Theme the Search Form for Drupal 6

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文