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...) |
(→相关的) |
||
(未显示2个用户的2个中间版本) | |||
第1行: | 第1行: | ||
== | == 描述== | ||
如果有搜索的话,显示当期请求的搜索查询。 | |||
可以在HTML属性中安全地使用这个标签(如在下面例子中的"搜索框"中)。 | |||
== | == 用法 == | ||
%%% <?php the_search_query(); ?> %%% | %%% <?php the_search_query(); ?> %%% | ||
== 例子 == | |||
== | === 在搜索框中显示搜索查询=== | ||
如果你刚刚执行了一个搜索,你可以在搜索框中显示最后的查询: | |||
<pre><form method="get" id="searchform" action="<?php bloginfo('url'); ?>/"> | <pre><form method="get" id="searchform" action="<?php bloginfo('url'); ?>/"> | ||
第24行: | 第22行: | ||
</form></pre> | </form></pre> | ||
=== 在结果网页中显示搜索查询 === | |||
在搜索结果的网页上,你可以显示搜索字符串 | |||
%%% <p>You searched for " | %%% <p>You searched for " | ||
<?php the_search_query() ?> | <?php the_search_query() ?> | ||
". Here are the results:</p>%%% | ". Here are the results:</p>%%% | ||
== | == 相关的 == | ||
* [[WordPress:Function_Reference/get_search_query|get_search_query]] 函数 | |||
{{ | {{PHP函数 标签 页底文字}} |
2008年9月16日 (二) 09:46的最新版本
描述[ ]
如果有搜索的话,显示当期请求的搜索查询。
可以在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:
%%%
相关的[ ]