Created
June 23, 2012 09:58
-
-
Save brokendish/2977762 to your computer and use it in GitHub Desktop.
WordpressのGoogleカスタム検索テンプレート(ModernStyle用)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Template Name: GoogleSearch | |
*/ | |
?> | |
<?php get_header(); ?> | |
<div id="content"> | |
<?php include_once(TEMPLATEPATH . '/topbanner.php'); ?> | |
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> | |
<div class="post clearfix" id="post-<?php the_ID(); ?>"> | |
<h2 class="title"><?php the_title(); ?></h2> | |
<div class="entry"> | |
<?php //------------------------------ここにGoogleから取得した「Custom Search Element のコード」を書くよ!------------S ?> | |
<div id="cse" style="width: 100%;">Loading</div> | |
<script src="http://www.google.com/jsapi" type="text/javascript"></script> | |
<script type="text/javascript"> | |
google.load('search', '1', {language : 'ja', style : google.loader.themes.V2_DEFAULT}); | |
google.setOnLoadCallback(function() { | |
var customSearchOptions = {}; | |
var imageSearchOptions = {}; | |
imageSearchOptions['layout'] = google.search.ImageSearch.LAYOUT_POPUP; | |
customSearchOptions['enableImageSearch'] = true; | |
customSearchOptions['imageSearchOptions'] = imageSearchOptions; var customSearchControl = new google.search.CustomSearchControl( | |
'abcdefghijk1234567890:123456789', customSearchOptions); | |
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); | |
customSearchControl.draw('cse'); | |
function parseParamsFromUrl() { | |
var params = {}; | |
var parts = window.location.search.substr(1).split('\x26'); | |
for (var i = 0; i < parts.length; i++) { | |
var keyValuePair = parts[i].split('='); | |
var key = decodeURIComponent(keyValuePair[0]); | |
params[key] = keyValuePair[1] ? | |
decodeURIComponent(keyValuePair[1].replace(/\+/g, ' ')) : | |
keyValuePair[1]; | |
} | |
return params; | |
} | |
var urlParams = parseParamsFromUrl(); | |
var queryParamName = "qa"; | |
if (urlParams[queryParamName]) { | |
customSearchControl.execute(urlParams[queryParamName]); | |
} | |
}, true); | |
</script> | |
<?php //------------------------------ここにGoogleから取得した「Custom Search Element のコード」を書くよ!------------E ?> | |
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) { the_post_thumbnail(array(300,225), array("class" => "alignleft post_thumbnail")); } ?> | |
<?php /* ここはいらないのでコメントアウト | |
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?> | |
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?> | |
*/ ?> | |
</div> | |
</div> | |
<?php /* ここはいらないのでコメントアウト | |
<?php comments_template(); ?> | |
*/ ?> | |
<?php endwhile; endif; ?> | |
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?> | |
</div> | |
</div> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment