WordPress中用于获取搜寻表单的PHP函数应用解析

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( '/' ) ) . '" >
 <p><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') .'" />
 </p>
 </form>';
 
 if ( $echo )
 echo apply_filters('get_search_form', $form);
 else
 return apply_filters('get_search_form', $form);
}
?>

以上就是安达网络工作室关于《WordPress中用于获取搜索表单的PHP函数使用解析》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: WordPress 搜索表单 PHP PHP编程
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
详解WordPress开发中用于获取分类及子页面的函数用法

get_category get_category 可能咱们平常接触的不多,但却是很有用,网上这个函数引见的貌似不多,所以明天...

Crayon Syntaxer代码高亮插件与fancybox图片暗箱抵触的处理办法

其实,这是一个历史遗留成绩,在最开端建站的时分就曾经呈现了,在知更鸟主题和Crayon Syntaxer这个插件之间...

从站内查用WordPress站内文章的完成办法

最近遇到一个从站内查用WordPress站内文章成绩,详细是这样的:需求在A站的首页或许侧边栏援用B站点的最新文...

WordPress主题Green-Park-2导航栏修正技巧

我网上找了很多处理导航计划的成绩,均无奈用于WordPress3.1之上,总会呈现其余成绩。而我所解说的这种办法...

WordPress在IIS效劳器上的伪动态设置办法(处理中文URL无奈拜访成绩)

咱们都晓得WordPress顺序很弱小,对搜寻引擎优化很敌对,然而有一点可能有些人还不是很分明,关于WordPress这样...

应用WordPress发送电子邮件的相干PHP函数用法解析

wp_mail() 函数用来发送邮件,相似于 PHP 的 mail() 函数。 默许的发件人称号是 WordPress,发件人邮箱是相...

需求提交

客服服务