首页 WordPress函数 WordPress加载搜索表单标签:get_search_form
正文 评论

WordPress加载搜索表单标签:get_search_form

WordPress模板标签get_search_form用于加载搜索表单,首先会尝试加载模板文件searchform.php,如果该文件不存在,则输出默认的搜索表单HTML。

get_search_form( bool $echo = true )

函数参数

$echo

布尔值,默认为true,即输出表单内容,如果为false,则只返回结果而不输出。

get_search_form默认输出XHTML版本的标签,如果要输出HTML5版本的标签,需要在主题文件中加入以下代码:

add_theme_support( \'html5\', array(\'search-form\',) );

XHTML版本的输出结果如下:

<form role=\"search\" method=\"get\" id=\"searchform\"  action=\"https://www.beizigen.com/\"><div><label  for=\"s\">搜索:</label><input type=\"text\" value=\"\" name=\"s\" id=\"s\" /><input type=\"submit\" id=\"searchsubmit\" value=\"搜索\" /></div></form>

HTML5版本的输出结果如下:

<form role=\"search\" method=\"get\"  action=\"https://www.beizigen.com/\"><label><span >搜索:</span><input type=\"search\"  placeholder=\"搜索&hellip;\" value=\"\" name=\"s\" /></label><input type=\"submit\"  value=\"搜索\" /></form>

扩展阅读

get_search_form()函数位于:wp-includes/general-template.php

相关函数:

  • get_header()
  • get_sidebar()
  • get_template_part()
  • comments_template()
  • get_footer()
-=||=-收藏赞 (0)
更多主题
v1.0.0
小程序收录免费WordPress主题:XCX主题
¥ 0 关注:22,481
详情
单栏极简文艺WordPress博客主题:Diaspora主题
¥ 0 关注:22,055
详情
简约黑白WordPress个人博客主题:Personal主题
¥ 0 关注:21,760
详情
功能丰富切轻量的WordPress虚拟资源主题:Rizhuti主题
¥ 599 关注:19,807
详情
v1.0.0
一款简约单栏的免费WordPress博客主题:itheme主题
¥ 0 关注:19,737
详情
v3.4.0
适用自媒体资讯的免费WordPress主题:Autumn主题
¥ 0 关注:16,834
详情
回复
暂无评论

不要再留垃圾评论了,主题君整理资源不容易,留几句鼓励的话吧。