首页 >

WordPress获取搜索表函数get_search_form用法

WordPress函数介绍-获得侧栏函数get_search_form详解。

WordPress教程

函数原型

get_search_form函数位于wp-includes/general-template.php函数原型如下:

function get_search_form( $echo = true ) {/** * Fires before the search form is retrieved, at the start of get_search_form(). * * @since 2.7.0 as 'get_search_form' action. * @since 3.6.0 * * @link https://core.trac.wordpress.org/ticket/19321 */do_action( 'pre_get_search_form' );$format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';/** * Filters the HTML format of the search form. * * @since 3.6.0 * * @param string $format The type of markup to use in the search form. *                       Accepts 'html5', 'xhtml'. */$format = apply_filters( 'search_form_format', $format );$search_form_template = locate_template( 'searchform.php' );if ( '' != $search_form_template ) {ob_start();require( $search_form_template );$form = ob_get_clean();} else {if ( 'html5' == $format ) {$form = '';} else {$form = '
';}}/** * Filters the HTML output of the search form. * * @since 2.7.0 * * @param string $form The search form HTML output. */$result = apply_filters( 'get_search_form', $form );if ( null === $result )$result = $form;if ( $echo )echo $result;elsereturn $result;}
函数介绍

使用此函数将查找主题目录searchform.php如果你的主题没有作为搜索表的文件 searchform.php, WordPress 默认表单代码如下:

<form role='search' method='get' id='searchform' action='">    

请注意,搜索表单需要一个 Get 方式(method=”get” )到你博客的主页,文本输入框应该被命名为 s (name=”s”),此外,它还必须包含与上述例子相同的内容 alabel 。

使用方法

如果传入true输出表,false 然后返回表单的字符串。


  • 暂无相关文章