我没有太多的PHP经验,但我正在尝试更新我网站的自定义主题代码以使用新的Google CSE。该网站已设置,以便标题有一个搜索栏,可将您重定向到搜索结果页面。 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>
非常感谢任何帮助!谢谢!
答案 0 :(得分:1)
只需替换旧的HTML代码
即可<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>
(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>
现在一切都将开始工作.. (现在您已使用Google自定义搜索替换默认搜索)