WordPress:Template Tags/the search query

来自站长百科
Xxf3325讨论 | 贡献2008年6月27日 (五) 10:00的版本 (新页面: == 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...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

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).


Usage

%%% <?php the_search_query(); ?> %%%


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>

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:

%%%

Related

模板:PHP Function Tag Footer