国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

WordPress中用于獲取搜索表單的PHP函數使用解析

2024-04-25 20:43:50
字體:
來源:轉載
供稿:網友

 

get_search_form 函數在 WordPress 中是用來提取預設的搜索表單或者默認的搜索表單的。因為官方這個函數沒有中文的,所以我就簡單寫了一下。

描述

get_search_form 函數在 WordPress 中是用來提取自定義搜索表單或者默認的搜索表單的。

顯示自定義表單還是顯示默認表單,完全取決于您的主題中是否有search.php文件,

如果有該文件,則自動調用該文件,如果沒有則顯示默認的搜索表單。

使用

<?php

get_search_form($echo = true)

?>

參數

$echo 布爾型,用來選擇顯示還是返回變量。

默認值:true

實例

沒你想象的復雜,其實就是這么簡單。

<?php

get_search_form();

?>

這里提一下,如果你需要整合谷歌自定義搜索那些的話,

你只要在你的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 = '<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);

}

?>

以上就是本文章的內容,希望對大家有所幫助

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临西县| 南投县| 南安市| 广元市| 大方县| 托克逊县| 合阳县| 沙雅县| 太谷县| 廊坊市| 枣庄市| 池州市| 湘西| 金沙县| 游戏| 河西区| 永兴县| 乌兰县| 桐城市| 杭锦后旗| 静海县| 札达县| 万安县| 安阳市| 广丰县| 自治县| 马龙县| 玉溪市| 泗洪县| 瓮安县| 高要市| 云林县| 周宁县| 黎城县| 云安县| 米林县| 吉木萨尔县| 嘉善县| 丰宁| 榆社县| 崇州市|