WordPress:Template Tags/the search query
来自站长百科
Description
描述
Displays the search query for the current request, if a search was made.
如果有搜索的话,显示当期请求的搜索查询。
This function can be used safely within HTML attributes (as in the "search box" example, below). 可以在HTML属性中安全地使用这个标签(如在下面例子中的"搜索框"中)。
Usage
%%% <?php the_search_query(); ?> %%%
用法
%%% <?php the_搜索_查询(); ?> %%%
Examples
Show search query in search box
例子
在搜索框中显示搜索查询
If you have just performed a search, you can show the last query in the search box:
如果你刚刚执行了一个搜索,你可以在搜索框中显示最后的查询:
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/"> <div> <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </div> </form>
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/"> <div> <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" /> <input type="submit" id="searchsubmit" value="Search" /> </div> </form>
Show search query in results page
在结果网页中显示搜索查询
You can display the search string on search result pages 在搜索结果的网页上,你可以显示搜索字符串
%%%
You searched for " <?php the_search_query() ?> ". Here are the results:
%%% %%%
You searched for " <?php the_搜索_查询() ?> "。这里是结果:
%%%
Related
- get_search_query function
- get_search_query filter