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函数使用解析》的一些看法。更多内容请查看本栏目更多内容!
咱们先来看一下什么是nofollow。NoFollow是Google几年前提出的一个新标签,目的是缩小渣滓留言。此标签标明...
要害字形容:性能 治理 内容 后盾 文章 分类 页面 文件 能够 删除 上一次教程咱们解说了应用Wordpress来撰...
WordPress的编辑器TinyMCE是一个十分弱小的工具,关于网页设计师来说,应用WordPress的编辑器TinyMCE是没什...
wordpress操作数据库用一个全局变量$wpdb来进行各种操作,应用的时分先在函数申明global $wpdb,而后调用它...
有一个一劳永逸的办法能够使wordpress博主当前上传插件都不必再手动激活,wordpress主动激活,办法很简略,...
很多博客都有本人的置顶文章,在默许状况下WP对置顶文章只是将它们的地位排在后面,除了地位差别外,跟其余...