加入收藏 | 设为首页 | 会员中心 | 我要投稿 佛山站长网 (https://www.0757zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > 建站资源 > 优化 > 正文

WordPress无缝集成Google自定义搜索引擎

发布时间:2013-03-24 18:49:55 所属栏目:优化 来源:站长网
导读:前几天突然发现本站的搜索功能出现了点问题,索性直接更改为Google自定义搜索引擎。可在折腾搜索功能的时候经历了一些坎坷,所以整理了下内容分享给大家。

<div class=“clear”></div>

</footer>

</article>

<?php endwhile;?>

<?php else : ?>

<article class=“post”>

<h2>没有找到任何内容</h2>

<?php get_search_form(); ?>

</article>

<?php endif; ?>

<div class=“navigation group”>

<div class=“wp-pagenavi”><?php par_pagenavi(9); ?></div>

</div>

</div>

<?php get_sidebar(); ?>

</div>

<?php get_footer(); ?>

我将它删除至只剩下一个大概的结构:

<?phpget_header();?> <div id="content"class="group"><span style="line-height: 1.6em;"></span> </div> <?phpget_footer();?>

去刚刚的自定义搜索引擎页面那获取代码吧,这是最后一步了。

#FormatImgID_3#

很显然普通的代码已经不能满足我们的需求了,下方点击获取V1代码。

将获得的代码与search.php合并:

<?phpget_header();?>

<div id=“content”class=“group”>

<div id='cse' style='width: 100%;'>

Loading

</div>

<script src='//www.google.com/jsapi' type='text/javascript'></script>

<script type='text/javascript'>google.load('search', '1', {language: 'zh-Hans', style: google.loader.themes.V2_DEFAULT});

google.setOnLoadCallback(function() {var customSearchOptions = {};var orderByOptions = {};orderByOptions[‘keys’] = [{label: ‘Relevance’, key: ‘’} , {label: ‘Date’, key: ‘date’}];

customSearchOptions[‘enableOrderBy’] = true;customSearchOptions[‘orderByOptions’] = orderByOptions;customSearchOptions[‘overlayResults’] = true;

var customSearchControl = new google.search.CustomSearchControl('002417144856058510941:uk_1aiwj0ok', customSearchOptions);

customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);var options = new google.search.DrawOptions();

options.setAutoComplete(true);customSearchControl.draw('cse', options);}, true);

</script>

<style type='text/css'>.gsc-control-cse {

font-family:Arial,sans-serif;border-color:#FFFFFF;background-color:#FFFFFF;}

.gsc-control-cse .gsc-table-result {font-family:Arial,sans-serif;

}

input.gsc-input, .gsc-input-box, .gsc-input-box-hover, .gsc-input-box-focus {border-color:#D9D9D9;

}

input.gsc-search-button, input.gsc-search-button:hover, input.gsc-search-button:focus {border-color:#666666;background-color:#CECECE;background-image:none;filter:none;}

.gsc-tabHeader.gsc-tabhInactive {border-color:#FF9900;background-color:#FFFFFF;}

.gsc-tabHeader.gsc-tabhActive {border-color:#E9E9E9;background-color:#E9E9E9;border-bottom-color:#FF9900}

.gsc-tabsArea {border-color:#FF9900;}

.gsc-webResult.gsc-result, .gsc-results .gsc-imageResult {border-color:#FFFFFF;background-color:#FFFFFF;}

.gsc-webResult.gsc-result:hover, .gsc-imageResult:hover {border-color:#FFFFFF;background-color:#FFFFFF;}

.gs-webResult.gs-result a.gs-title:link, .gs-webResult.gs-result a.gs-title:link b, .gs-imageResult a.gs-title:link, .gs-imageResult a.gs-title:link b {color:#0000CC;}

.gs-webResult.gs-result a.gs-title:visited, .gs-webResult.gs-result a.gs-title:visited b, .gs-imageResult a.gs-title:visited, .gs-imageResult a.gs-title:visited b {color:#0000CC;}

.gs-webResult.gs-result a.gs-title:hover, .gs-webResult.gs-result a.gs-title:hover b, .gs-imageResult a.gs-title:hover, .gs-imageResult a.gs-title:hover b {color:#0000CC;}

.gs-webResult.gs-result a.gs-title:active, .gs-webResult.gs-result a.gs-title:active b, .gs-imageResult a.gs-title:active, .gs-imageResult a.gs-title:active b {color:#0000CC;}

.gsc-cursor-page {color:#0000CC;}a.gsc-trailing-more-results:link {color:#0000CC;}

.gs-webResult .gs-snippet, .gs-imageResult .gs-snippet, .gs-fileFormatType {color:#000000;}

.gs-webResult div.gs-visibleUrl, .gs-imageResult div.gs-visibleUrl {color:#008000;}.gs-webResult div.gs-visibleUrl-short {color:#008000;}.gs-webResult div.gs-visibleUrl-short {display:none;}

(编辑:佛山站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读