WordPress:Template Tags/the search query

来自站长百科
跳转至: 导航、​ 搜索

描述[ ]

如果有搜索的话,显示当期请求的搜索查询。

可以在HTML属性中安全地使用这个标签(如在下面例子中的"搜索框"中)。

用法[ ]

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

例子[ ]

在搜索框中显示搜索查询[ ]

如果你刚刚执行了一个搜索,你可以在搜索框中显示最后的查询:

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


在结果网页中显示搜索查询[ ]

在搜索结果的网页上,你可以显示搜索字符串

%%%

You searched for " <?php the_search_query() ?> ". Here are the results:

%%%

相关的[ ]