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

首頁(yè) > CMS > Wordpress > 正文

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

2024-09-07 00:40:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了WordPress中用于獲取搜索表單的PHP函數(shù)使用解析,即get_search_form函數(shù)的基本用法,需要的朋友可以參考下。

get_search_form 函數(shù)在 WordPress 中是用來(lái)提取預(yù)設(shè)的搜索表單或者默認(rèn)的搜索表單的。因?yàn)楣俜竭@個(gè)函數(shù)沒有中文的,所以我就簡(jiǎn)單寫了一下。

描述

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

顯示自定義表單還是顯示默認(rèn)表單,完全取決于您的主題中是否有search.php文件,如果有該文件,則自動(dòng)調(diào)用該文件,如果沒有則顯示默認(rèn)的搜索表單。

使用

  1. <?php 
  2.   get_search_form($echo = true)  
  3. ?> 

參數(shù)

$echo 布爾型,用來(lái)選擇顯示還是返回變量。

默認(rèn)值:true

實(shí)例

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

  1. <?php 
  2.   get_search_form();  
  3. ?> 

這里提一下,如果你需要整合谷歌自定義搜索那些的話,你只要在你的search.php 文件中將自定義的部分代碼放入即可嘍,當(dāng)然你需要設(shè)定樣式。

函數(shù)源代碼

  1. <?php 
  2.  /** 
  3.  * Display search form. 
  4.  * 
  5.  * Will first attempt to locate the searchform.php file in either the child or 
  6.  * the parent, then load it. If it doesn't exist, then the default search form 
  7.  * will be displayed. The default search form is HTML, which will be displayed. 
  8.  * There is a filter applied to the search form HTML in order to edit or replace 
  9.  * it. The filter is 'get_search_form'. 
  10.  * 
  11.  * This function is primarily used by themes which want to hardcode the search 
  12.  * form into the sidebar and also by the search widget in WordPress. 
  13.  * 
  14.  * There is also an action that is called whenever the function is run called, 
  15.  * 'get_search_form'. This can be useful for outputting JavaScript that the 
  16.  * search relies on or various formatting that applies to the beginning of the 
  17.  * search. To give a few examples of what it can be used for. 
  18.  * 
  19.  * @since 2.7.0 
  20.  * @param boolean $echo Default to echo and not return the form. 
  21.  */ 
  22. function get_search_form($echo = true) { 
  23.  do_action( 'get_search_form' ); 
  24.    
  25.  $search_form_template = locate_template('searchform.php'); 
  26.  if ( '' != $search_form_template ) { 
  27.  require($search_form_template); 
  28.  return
  29.  } 
  30.    
  31.  $form = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '" > 
  32.  <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label> 
  33.  <input type="text" value="' . get_search_query() . '" name="s" id="s" /> 
  34.  <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" /> 
  35.  </div> 
  36.  </form>'; 
  37.    
  38.  if ( $echo ) 
  39.  echo apply_filters('get_search_form'$form); 
  40.  else 
  41.  return apply_filters('get_search_form'$form); 
  42. ?>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 阳原县| 宜兰市| 夏河县| 旺苍县| 原平市| 延长县| 无锡市| 屯昌县| 金溪县| 永胜县| 宣汉县| 瑞丽市| 搜索| 邛崃市| 通化县| 彭阳县| 子洲县| 浦城县| 巴彦淖尔市| 堆龙德庆县| 洪泽县| 商洛市| 邵武市| 武穴市| 西贡区| 婺源县| 兰西县| 会昌县| 武宣县| 开远市| 监利县| 济宁市| 罗源县| 凤山市| 永胜县| 石柱| 金山区| 禹城市| 慈溪市| 杭锦旗| 河曲县|