Additional Search Blocks in Drupal
Ever need to create additional search blocks for your Drupal installation? One use might be so that you can theme or position the block differently depending on which page the block appears on.
It's actually quite easy to do - all you need to do is create a new module that implements "hook_block" and then create a new block and call the "search_box" function (from search.module) to populate the box with the correct form elements. Here's the code:
function mymodule_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks[0]['info'] = t('Quicktips Search form');
return $blocks;
}
else if ($op == 'view') {
switch($delta) {
case 0:
if (user_access('search content')) {
$block['content'] = search_box('search_block_form');
$block['subject'] = t('Search');
}
break;
}
return $block;
}
}
if ($op == 'list') {
$blocks[0]['info'] = t('Quicktips Search form');
return $blocks;
}
else if ($op == 'view') {
switch($delta) {
case 0:
if (user_access('search content')) {
$block['content'] = search_box('search_block_form');
$block['subject'] = t('Search');
}
break;
}
return $block;
}
}
In this case, the parameter "search_block_form" is the form_id that will be assigned to the search form. Once you install the module, you'll be able to go to the admin area and place your new search block anywhere you'd like.

Post new comment