用Google自定义搜索替代wordpress自带搜索别忘了加上几行代码
如果选择,当然选择Google自定义搜索,这有很多好处,比如服务器带宽等等。
本文不详细讲诉怎么用Google自定义搜索替代wordpress的自带搜索功能。
如果你的Search.php页面的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <div id="cse" style="width: 640px;">loading...</div> <script src="http://www.google.com/jsapi" type="text/javascript"></script> <script type="text/javascript"> google.load('search', '1', {language : 'zh-CN'}); google.setOnLoadCallback(function() { var customSearchControl = new google.search.CustomSearchControl('你的Google 自定义搜索ID'); customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); customSearchControl.draw('cse'); var match = location.search.match(/s=([^&]*)(&|$)/); if(match && match[1]){//从if这里是新添加的代码开始 var search = decodeURIComponent(match[1]); customSearchControl.execute(search); } });//这里是新添加的代码结束 |
请自己对比你在Google那里最终取到的代码的除去CSS(style)部分与上面代码有区别的地方,这里也已经在代码中标注了,用添加的这几行代码去替代你不同的地方.