麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網(wǎng)站 > 建站經(jīng)驗 > 正文

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

2024-04-25 20:43:50
字體:
供稿:網(wǎng)友

 

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

描述

get_search_form 函數(shù)在 WordPress 中是用來提取自定義搜索表單或者默認(rèn)的搜索表單的。

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

如果有該文件,則自動調(diào)用該文件,如果沒有則顯示默認(rèn)的搜索表單。

使用

<?php

get_search_form($echo = true)

?>

參數(shù)

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

默認(rèn)值:true

實例

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

<?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);

}

?>

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产九九热 | 黑人一级片视频 | 深夜免费视频 | 羞羞的视频免费在线观看 | 成人综合一区二区 | www.guochan | 欧美色淫 | 日本在线不卡一区二区 | 中国女警察一级毛片视频 | 国产精品自拍av | 精品国产一级毛片 | 日韩精品dvd | gogo全球大胆高清人露出91 | 精品国产一级毛片 | 国产精品jk白丝蜜臀av软件 | 久久久久久亚洲综合影院红桃 | 久久久久亚洲视频 | 久久久久久久久久一本门道91 | 久久99精品久久久久久国产越南 | 青青草免费观看 | 久久国产精品二国产精品中国洋人 | 成人做爽爽爽爽免费国产软件 | 欧美人的天堂一区二区三区 | 亚洲片在线观看 | 久久一级 | 亚洲午夜一区二区三区 | 91美女视频在线 | 国产精品久久久久久238 | 久草在线观看福利视频 | 国产成人精品网站 | 国产一级αv片免费观看 | www.91sao| 欧洲精品色 | 国产女厕一区二区三区在线视 | 日本精品婷婷久久爽一下 | 欧美巨根| 久久久久久久亚洲视频 | 国产激情视频在线 | 国内精品久久久久久久久久 | 99热高清 | 午夜影视一区二区 |