我没有太多的PHP经验,但我正在尝试更新我的网站的自定义主题代码以使用新的Google CSE . 该网站已设置,以便 Headers 有一个搜索栏,可将您重定向到搜索结果页面 . header.php中的搜索条形码如下:
<form method="get" action="<?php bloginfo('url'); ?>" class="ui-form dark search">
<label for="f-search"><i class="icon-search"></i> <span class="alt">Search</span></label>
<input type="text" name="s" id="f-search" placeholder="Search" />
</form>
搜索结果页面:
<script src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('search', '1');
google.setOnLoadCallback(function() {
var SEARCH = new google.search.CustomSearchControl('010282947182076583221:xjxtd-etbp0');
SEARCH.draw('search-results');
SEARCH.execute("<?php the_search_query(); ?>");
});
</script>
这是来自Google的新CSE代码:
<script>
(function() {
var cx = '015983680008294815385:py6fsnsv2fc';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
任何帮助都非常感谢!谢谢!
1 回答
只需替换旧的HTML代码即可
WITH
这就是现在它将开始工作..(现在你已经用Google自定义搜索替换了默认搜索)