WordPress中用于获取搜索表单的PHP函数使用解析
|
《:WordPress中用于获取搜索表单的PHP函数使用解析》要点: get_search_form 函数在 WordPress 中是用来提取预设的搜刮表单或者默认的搜刮表单的.因为官方这个函数没有中文的,所以我就简单写了一下.PHP教程 描述 使用 <?php get_search_form($echo = true) ?> 参数 实例 <?php get_search_form(); ?> 这里提一下,如果你必要整合谷歌自定义搜索那些的话, 函数源代码
<必修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);
}
必修>
欢迎参与《:WordPress中用于获取搜索表单的PHP函数使用解析》讨论,分享您的想法,编程之家 52php.cn为您提供专业教程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
