
前几天突然发现本站的搜索功能出现了点问题,索性直接更改为Google自定义搜索引擎。可在折腾搜索功能的时候经历了一些坎坷,所以整理了下内容分享给大家。
1、创建搜索引擎
登入https://accounts.google.com/ServiceLogin?continue=http://www.google.com/cse/all&service=cprose&hl=zh-CN&gl=us&passive=true,若没有Google的帐号可去简单注册一个。登入后,我们开始创建一个“定制Google搜索引擎“,如下图:
#FormatImgID_0#
在输入框内输入要搜索的网站,这里需要注意的是索引整个网站还是只是文章部分。若是整个网站直接按照图中的提示填写即可,若是单纯搜索全部文章页面就可能会麻烦些。
若只想让Google搜索网站的文章页面,首先要确定WordPress固定链接的设置。
默认:http://www.domain.com/?p=123 在输入框中填入http://www.domain.com/?p=*
日期和名称型:http://www.domain.com/2013/03/19/sample-post/ 在输入框中填入http://www.domain.com/年份/月份/天/*
月份和名称型以此类推
数字型:http://www.domain.com/archives/123 在输入框中填入http://www.domain.com/archives/*
文章型:http://www.mywpku.com/sample-post/ 在输入框中填入http://www.mywpku.com/*/
伪静态HTML型:http://www.mywpku.com/sample-post.html 在输入框中填入http://www.mywpku.com/*.html
其余可以此类推。
可别忘了选择网站语言哦!完成后下一步吧。
#FormatImgID_1#
2、更改搜索外观 更改原主题文件
接下来可以根据需要来更改Google搜索页面的背景颜色,按钮颜色等等。不过最重要的一点是将布局更改为全宽:
#FormatImgID_2#
接下来我们对主题的搜索页面进行修改。在WordPress中输入一个搜索词,它将会显示出搜索页面,并按照搜索词来显示内容。不过现在我们需要变一下:显示出搜索页面后按照输入的内容来调用Google搜索引擎帮你搜索。
在主题目录中找到类似于search.php这样的文件,以我的主题来做个示例:
<?php get_header(); ?>
<div id=“content” class=“group”>
<div id=“content_main”>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $fmimg = get_post_meta($post->ID, “fmimg_value”, true); ?>
<article <?php post_class() ?> id=“post-<?php the_ID(); ?>” data-posttime=“<?php the_time(‘Y-m-d H:i:s’); ?>”><header>
<figure class=“post_category”><?php the_category(‘ ’); ?></figure>
<a href=“<?php the_permalink(); ?>” rel=“bookmark” title=“<?php the_title(); ?>” target=‘_blank’><?php has_post_thumbnail(); if ( has_post_thumbnail() ){ the_post_thumbnail(‘fmimg’); } elseif($fmimg) { ?><img src=“<?php echo $fmimg; ?>” /><?php } else { ?><img src=“<?php echo catch_that_image(); ?>” /><?php } ?></a><strong><h4 class=“post_title”>
<a href=“<?php the_permalink(); ?>” rel=“bookmark” title=“<?php the_title(); ?>” target=‘_blank’><?php the_title(); ?></a></h4></strong>
</header>
<div class=“entry group”>
<?php echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 180,“。。。”,“utf-8”); ?></div>
<footer class=“post_meta”>
Written By
<a href=“<?php echo get_author_posts_url(get_the_author_meta( ‘ID’ )); ?>” rel=“nofollow”><?php echo the_author_meta( ‘display_name’ ); ?></a>
<span class=“info-category-icon”><?php the_category(‘, ’) ?></span>
<span class=“info-comment-icon”><?php comments_popup_link (‘沙发还在’,‘还有板凳’,‘%条评论’); ?> <?php edit_post_link(‘编辑本文’, ‘’, ‘’); ?></span>
<a href=“<?php the_permalink(); ?>” title=“<?php the_title(); ?>” class=“more” target=‘_blank’><img src=“http://upload.chinaz.com/2013/0321/1363835608792.png”></a>
(编辑:佛山站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|