我目前在我的网站标题中有一个搜索框(在每个页面上),它将搜索查询发送到一个名为“search”的页面,该页面使用一个名为searchpage
. 页面/模板使用Google自定义搜索来显示结果。
现在,这一切都很好,但我想使用内置的WordPress搜索也返回同一页面上的搜索结果,在Google结果之上。有效地使用1个搜索框在同一页面上返回2组结果;1个用于WordPress,1个用于Google自定义搜索。
这可能吗?我该怎么做?
我目前在我的网站标题中有一个搜索框(在每个页面上),它将搜索查询发送到一个名为“search”的页面,该页面使用一个名为searchpage
. 页面/模板使用Google自定义搜索来显示结果。
现在,这一切都很好,但我想使用内置的WordPress搜索也返回同一页面上的搜索结果,在Google结果之上。有效地使用1个搜索框在同一页面上返回2组结果;1个用于WordPress,1个用于Google自定义搜索。
这可能吗?我该怎么做?
默认情况下,标准搜索结果也可以使用主题文件格式化search.php
. 你不需要为此创建一个“假”页面。
如果不包含页面中的任何内容,并且只使用主题文件,则可以重命名searchpage.php
到search.php
它会起作用的。如果您确实有一些内容来自写在管理区域的页面,那么您必须自己查询(使用get_posts()
或者另一种方式),因为标准循环将只包含搜索结果,而不包含特定页面。
因此,如果您想将内部WordPress搜索结果添加到页面中,只需在顶部添加一个经典循环,就会显示结果。
您需要一个Google自定义搜索引擎用以下代码替换您的搜索表单:
<form action="http://your.blog.url/index.php?s=" id="cse-search-box" class="searchform">
<input type="hidden" name="cx" value="your_CSE_ID" />
<input type="hidden" name="cof" value="FORID:10" />
<input type="hidden" name="ie" value="UTF-8" />
<label for="q">Search</label>
<input type="hidden" name="s" id="s" value="" />
<input type="text" name="q" id="q" class="keyword" />
</form>
<script>
jQuery(\'#q\').bind(\'change\', function() {
jQuery(this).val(function(i, val) {
jQuery(\'#s\').val(val);
return val;
});
});
</script>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=de"></script>
将此代码用于搜索结果(显示内部结果后):<div id="cse-search-results"></div>
<script type="text/javascript">
var googleSearchIframeName = "cse-search-results";
var googleSearchFormName = "cse-search-box";
var googleSearchFrameWidth = 600;
var googleSearchDomain = "www.google.com";
var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
There\'s also the Google Custom Search plugin
如何使permalink可用于搜索结果页/?s=一+二+确定到/搜索/一-二确定/感谢