WordPress中用於擷取搜尋表單的PHP函數使用解析,wordpressphp
get_search_form 函數在 WordPress 中是用來提取預設的搜尋表單或者預設的搜尋表單的。因為官方這個函數沒有中文的,所以我就簡單寫了一下。
描述
get_search_form 函數在 WordPress 中是用來提取自訂搜尋表單或者預設的搜尋表單的。
顯示自訂表格單還是顯示預設表單,完全取決於您的主題中是否有search.php檔案,
如果有該檔案,則自動調用該檔案,如果沒有則顯示預設的搜尋表單。
使用
<?php get_search_form($echo = true) ?>
參數
$echo 布爾型,用來選擇顯示還是返回變數。
預設值:true
執行個體
沒你想象的複雜,其實就是這麼簡單。
<?php get_search_form(); ?>
這裡提一下,如果你需要整合Google自訂搜尋那些的話,
你只要在你的search.php 檔案中將自訂的部分代碼放入即可嘍,當然你需要設定樣式。
函數原始碼
<?php /** * Display search form. * * Will first attempt to locate the searchform.php file in either the child or * the parent, then load it. If it doesn't exist, then the default search form * will be displayed. The default search form is HTML, which will be displayed. * There is a filter applied to the search form HTML in order to edit or replace * it. The filter is 'get_search_form'. * * This function is primarily used by themes which want to hardcode the search * form into the sidebar and also by the search widget in WordPress. * * There is also an action that is called whenever the function is run called, * 'get_search_form'. This can be useful for outputting JavaScript that the * search relies on or various formatting that applies to the beginning of the * search. To give a few examples of what it can be used for. * * @since 2.7.0 * @param boolean $echo Default to echo and not return the form. */function get_search_form($echo = true) { do_action( 'get_search_form' ); $search_form_template = locate_template('searchform.php'); if ( '' != $search_form_template ) { require($search_form_template); return; } $form = ''; if ( $echo ) echo apply_filters('get_search_form', $form); else return apply_filters('get_search_form', $form);}?>
您可能感興趣的文章:
- WordPress開發中用於標題顯示的相關函數使用解析
- WordPress中調試縮圖的相關PHP函數使用解析
- 配置解決Nginx伺服器中WordPress路徑不自動加斜杠問題
- 在WordPress中使用wp_count_posts函數來統計文章數量
- 詳解WordPress中調用評論模板和迴圈輸出評論的PHP函數
- 詳解WordPress中分類函數wp_list_categories的使用
- WordPress中限制非管理使用者在文章後只能評論一次
- 詳解WordPress中建立和添加過濾器的相關PHP函數
- 詳解WordPress開發中wp_title()函數的用法
http://www.bkjia.com/PHPjc/1088777.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1088777.htmlTechArticleWordPress中用於擷取搜尋表單的PHP函數使用解析,wordpressphp get_search_form 函數在 WordPress 中是用來提取預設的搜尋表單或者預設的搜尋表單的。...