WordPress 搜索查询
我在我的 WordPress 3.1 网站中添加了以下代码在我的 sidebar.php 文件底部:
<div id="search_box">
<form id="searchform" action="http://www.service.com/" method="get" role="search">
<input id="s" type="text" name="s" class="search" value="Search site" size="19" maxlength="80" id="white_box" onfocus="if (this.value=='Search site') this.value = ''"/>
<input id="searchsubmit" type="image" class="submit" value="submit" src="<?php bloginfo( 'template_url' ); ?>/images/search_btn.jpg" />
</form>
</div>
由于我自己编写了这个搜索过程,当我在搜索文本框中放置一些文本并按“搜索”按钮时,看起来好像是在我的主题中调用页面 search.php 并显示结果。
问题:
1)它在哪里/如何知道我何时按下“搜索”按钮并调用 search.php?
2)如果可能的话,我怎样才能将其更改为调用不同的php文件而不是search.php
谢谢。
I have added within my WordPress 3.1 site, the following code at the bottom of my sidebar.php file:
<div id="search_box">
<form id="searchform" action="http://www.service.com/" method="get" role="search">
<input id="s" type="text" name="s" class="search" value="Search site" size="19" maxlength="80" id="white_box" onfocus="if (this.value=='Search site') this.value = ''"/>
<input id="searchsubmit" type="image" class="submit" value="submit" src="<?php bloginfo( 'template_url' ); ?>/images/search_btn.jpg" />
</form>
</div>
As I have coded this search process myself, when I place a some text within my search text box and press the "Search" button, it looks as if, is is calling the page search.php within my theme and displaying the results.
Questions:
1) where/how does it know when I press the "Search" button to go off and call search.php?
2) if possible only, how can I change it to call a different php file instead of the search.php
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用模板过滤器
并将模板更改为
Use template filter
and change the template as
-1。对 WP 站点的所有请求都会转到一个页面,该页面根据特定条件路由它们。因此,当执行搜索时,它知道这是一次搜索并定向到 search.php 页面。
具体来说,它会转到加载 wp-blog-header.php 的 index.php。
-2:您需要了解的所有内容都应该在这里: http://codex.wordpress.org /Creating_a_Search_Page#Using_the_page.php
-1. All requests for a WP site go to a single page that routes them based upon specific criteria. Thus when a search is performed it knows that it is a search and directs to the search.php page.
Specifically it goes to index.php that loads wp-blog-header.php.
-2: Everything you need to know should be right here: http://codex.wordpress.org/Creating_a_Search_Page#Using_the_page.php
如果 WordPress 看到“s”GET 变量,则认为该请求是搜索。
您可以挂钩
template_redirect
操作(在主题的functions.php
文件中)并加载不同的模板,如下所示:Wordpress assumes the request is a search if it sees an 's' GET variable.
You can hook into the
template_redirect
action (in your theme'sfunctions.php
file) and load a different template like so: