Drupal搜索結果頁面中會出現一個搜索表單,與置頂的表單有重複的不好之處,另外,我也想在AMP頁面等特殊情況下去掉搜索結果頁中的表單。
以前好些在網上搜過有修改CSS的辦法來隐藏表單的顯示,今天又找到Drupal的hook_form_alter這個API調用辦法,測試有效,記錄如下:
function my_module_name_form_alter(&$form, &$form_state, $form_id) { // We have to be careful to alter only the contact site form, // as this hook is used for every form the system uses. if($form_id == 'contact_site_form'){//修改聯系我們表單 $form['referer'] = array( '#type' => 'hidden', '#title' => t('REFERER'), '#required' => FALSE, '#maxlength' => 255, '#default_value' => $_SERVER['HTTP_REFERER'], ); } if ($form_id == 'search_form' && $_GET['q'] != 'search') {//隐藏搜索表單 unset($form['basic']); unset($form['advanced']); } }
還有帖子說調用其它的API,例如:
function mytheme_page_alter(&$page) { // This assumes everything being output in the "content" page region. // Logged in if (!empty($page['content']['system_main']['content']['search_form'])) { unset($page['content']['system_main']['content']['search_form']); } // Not logged in if (!empty($page['content']['system_main']['search_form'])) { unset($page['content']['system_main']['search_form']); } }
這個辦法沒有試過,記錄下來備用。
评论2
我一般是創建一個 view page 來代替默認搜索頁。
我一般是創建一個 view page 來代替默認搜索頁。嗯
嗯,我們在有些情況下也用views來替代drupal原帶的搜索。