首页建站经验 WordPress中用于获取搜索表单的PHP函数使用解析

WordPress中用于获取搜索表单的PHP函数使用解析

 get_search_form 函数在 WordPress 中是用来提取预设的搜索表单或者默认的搜索表单的。因为官方这个函数没有中文的,所以我就简单写了一下。描述get_search_form 函数在 Wo…

 

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 = '

';

if ( $echo )

echo apply_filters('get_search_form', $form);

else

return apply_filters('get_search_form', $form);

}

?>

以上就是本文章的内容,希望对大家有所帮助

本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/jianzhan/jingyan/19084.html
上一篇修复ecshop注入XSS三个漏洞方法
下一篇 discuz教程:标题的最少字数限制设置方法
admin

作者: admin

这里可以再内容模板定义一些文字和说明,也可以调用对应作者的简介!或者做一些网站的描述之类的文字或者HTML!

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

    工作时间:周一至周五,9:00-17:30,节假日休息

    关注微信
    微信扫一扫关注我们

    微信扫一扫关注我们

    关注微博
    返回顶部