WordPress中用于獲取搜索表單的PHP函數(shù)使用解析
get_search_form 函數(shù)在 WordPress 中是用來(lái)提取預(yù)設(shè)的搜索表單或者默認(rèn)的搜索表單的。因?yàn)楣俜竭@個(gè)函數(shù)沒(méi)有中文的,所以我就簡(jiǎn)單寫(xiě)了一下。
描述
get_search_form 函數(shù)在 WordPress 中是用來(lái)提取自定義搜索表單或者默認(rèn)的搜索表單的。
顯示自定義表單還是顯示默認(rèn)表單,完全取決于您的主題中是否有search.php文件,
如果有該文件,則自動(dòng)調(diào)用該文件,如果沒(méi)有則顯示默認(rèn)的搜索表單。
使用
<?php get_search_form($echo = true) ?>
參數(shù)
$echo 布爾型,用來(lái)選擇顯示還是返回變量。
默認(rèn)值:true
實(shí)例
沒(méi)你想象的復(fù)雜,其實(shí)就是這么簡(jiǎn)單。
<?php get_search_form(); ?>
這里提一下,如果你需要整合谷歌自定義搜索那些的話,
你只要在你的search.php 文件中將自定義的部分代碼放入即可嘍,當(dāng)然你需要設(shè)定樣式。
函數(shù)源代碼
<?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 = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '" > <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label> <input type="text" value="' . get_search_query() . '" name="s" id="s" /> <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" /> </div> </form>'; if ( $echo ) echo apply_filters('get_search_form', $form); else return apply_filters('get_search_form', $form); } ?>
- 調(diào)用WordPress函數(shù)統(tǒng)計(jì)文章訪問(wèn)量及PHP原生計(jì)數(shù)器的實(shí)現(xiàn)
- 詳解WordPress中用于更新和獲取用戶選項(xiàng)數(shù)據(jù)的PHP函數(shù)
- 解析WordPress中控制用戶登陸和判斷用戶登陸的PHP函數(shù)
- 編寫(xiě)PHP腳本清除WordPress頭部冗余代碼的方法講解
- 是 WordPress 讓 PHP 更流行了 而不是框架
- WordPress主題制作中自定義頭部的相關(guān)PHP函數(shù)解析
- WordPress中調(diào)試縮略圖的相關(guān)PHP函數(shù)使用解析
- WordPress開(kāi)發(fā)中用于獲取近期文章的PHP函數(shù)使用解析
- WordPress開(kāi)發(fā)中自定義菜單的相關(guān)PHP函數(shù)使用簡(jiǎn)介
- 在CentOS系統(tǒng)上從零開(kāi)始搭建WordPress博客的全流程記錄
相關(guān)文章
php實(shí)現(xiàn)獲取本年,本月,本周時(shí)間戳和日期格式
這篇文章主要為大家詳細(xì)介紹了php實(shí)現(xiàn)獲取本年、本月、本周時(shí)間戳和日期格式的相關(guān)方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以學(xué)習(xí)一下2023-12-12PHP抽象工廠模式Abstract Factory Pattern優(yōu)點(diǎn)與實(shí)現(xiàn)方式
這篇文章主要介紹了PHP抽象工廠模式Abstract Factory Pattern優(yōu)點(diǎn)與實(shí)現(xiàn)方式,抽象工廠模式是一種創(chuàng)建型模式,它提供了一種創(chuàng)建一系列相關(guān)或相互依賴(lài)對(duì)象的最佳方式2023-03-03分享一個(gè)超好用的php header下載函數(shù)
這篇文章主要為大家分享一個(gè)超好用的php header下載函數(shù),需要的朋友可以參考下2014-01-01php使用pdo連接報(bào)錯(cuò)Connection failed SQLSTATE的解決方法
這篇文章主要介紹了php使用pdo連接報(bào)錯(cuò)Connection failed SQLSTATE的解決方法,涉及針對(duì)配置文件的修改,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2014-12-12PHP類(lèi)與對(duì)象中的private訪問(wèn)控制的疑問(wèn)
在手冊(cè)中遇到了一個(gè)沒(méi)想明白的問(wèn)題,記錄一下,方便需要的朋友2012-11-11PHP_NETWORK_GETADDRESSES: GETADDRINFO FAILED問(wèn)題解決辦法
這篇文章主要介紹了PHP_NETWORK_GETADDRESSES: GETADDRINFO FAILED問(wèn)題解決辦法,需要的朋友可以參考下2014-05-05