如何在drupal中编辑搜索区域
在我的网站 www.rchealth.co.uk 中,我想添加搜索。
我已启用搜索模块并且搜索块位于标题中,现在我想自定义搜索外观以使其看起来更好。
我搜索并找到了一些方法,例如 http://systemseed.com/blog /how-customise-search-box-drupal-6 和 http://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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您说搜索块位于标题中...您的意思是主题搜索吗?您使用的代码用于块搜索表单。
未以管理员身份登录时看不到搜索表单的最可能原因是您没有向匿名(可能还经过身份验证)用户授予使用“搜索”的正确权限。
要更改主题标题中主题搜索的外观/感觉/功能,您始终可以使用模板文件(
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