Skip to content

Instantly share code, notes, and snippets.

@andandehei
Last active January 3, 2016 13:09
Show Gist options
  • Save andandehei/8467338 to your computer and use it in GitHub Desktop.
Save andandehei/8467338 to your computer and use it in GitHub Desktop.
wordpress教程:wordpress网站添加谷歌Google站内搜索 所用到的代码
<? php
//第一次代码
<script type="text/javascript">
google.load('search', '1', {language : 'zh-CN'});
google.setOnLoadCallback(function(){
var customSearchControl = new google.search.CustomSearchControl('003292911367075971799:8iziecydkbw');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.draw('cse');
var match = location.search.match(/q=([^&]*)(&|$)/);
if(match && match[1]){
var search = decodeURIComponent(match[1]);
customSearchControl.execute(search);
}
});
</script>
//第二次代码
<?php
/*
Template Name: 谷歌搜索
*/
?>
//第三次代码
<div id="cse" style="width: 100%;">Loading</div>
你自己的google自定义搜索代码
<link rel="stylesheet" href="http://www.google.com.hk/cse/style/look/shiny.css" type="text/css" />
//第四次代码
<div id="search">
<form class="search_form" method="get" action="/search" <?php if(cmp_get_option( 'search_target' )) echo 'target="_blank"'; ?> >
<?php echo $search_id ?>
<input class="left" type="text" name="q" id="search-txt" value="<?php _e( 'Search …' , 'cmp' ) ?>" onfocus="if (this.value == '<?php _e( 'Search …' , 'cmp' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search …' , 'cmp' ) ?>';}" x-webkit-speech />
<button type="submit" class="tip-bottom" title="<?php _e( 'Search' , 'cmp' ) ?>"><i class="icon-search icon-white"></i></button>
</form>
</div>
//第五次代码
method=”get”
action=”/search”
name=”q”
//第六次代码
var match = location.search.match(/q=([^&]*)(&|$)/);
if(match && match[1]){
var search = decodeURIComponent(match[1]);
customSearchControl.execute(search);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment