见很多人都使用google自定义搜索代替wordpress的搜索功能....我今天也弄一个,效果还不错的. ..![](http://zarva.org/wp-content/plugins/x-emotions/emotions/QQ/13.gif)
网上的教程都很不详细,初次使用wordpress的网友们都不明白..今天.我就来完整的记录出来...
第一步:创建一个空白的googlesearch.php页面模板
,在里边输入
<?php
/*
Template Name: Google 自定义搜索..
*/
?>
然后在FTP,把googlesearch.php上传到wp-content/themes/当前主题目录,例如我的主题是ZarVa,就上传到wp-content/themes/ZarVa就行了.
在WordPress后台,"外观"-->"编辑".
![](http://oimagea2.ydstatic.com/image?url=http%3A%2F%2Flh4.ggpht.com%2F_IKN3boH2VZ0%2FSbS3N398fiI%2FAAAAAAAAGY0%2F4YMKeMMNjPY%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E3.png.png&w=650)
就可以看到刚才上传的googlesearch.php文件了.
![](http://oimagea2.ydstatic.com/image?url=http%3A%2F%2Flh5.ggpht.com%2F_IKN3boH2VZ0%2FSbS38xbN5aI%2FAAAAAAAAGZU%2FBDNL3tnnJAU%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E4.png.png&w=650)
打开single.php
把里边的代码复制到googlesearch.php文件下边.
![](http://oimagec1.ydstatic.com/image?url=http%3A%2F%2Flh6.ggpht.com%2F_IKN3boH2VZ0%2FSbS5GDGpNTI%2FAAAAAAAAGaU%2Fz-zpPkFEuhA%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E6.png.png&w=650)
然后点下边的"更新文件"保存.
在WordPress后台,选择"页面"--->"添加页面"
![](http://oimagea1.ydstatic.com/image?url=http%3A%2F%2Flh3.ggpht.com%2F_IKN3boH2VZ0%2FSbS8n-P7zwI%2FAAAAAAAAGbU%2FZbktS69Kzxg%2Fs800%2F%25E6%25B7%25BB%25E5%258A%25A0%25E9%25A1%25B5%25E9%259D%25A2.png.png&w=650)
标题就写search,要和刚才填写"显示搜索结果的网址"相同
![](http://oimagea7.ydstatic.com/image?url=http%3A%2F%2Flh6.ggpht.com%2F_IKN3boH2VZ0%2FSbS9hE3Zi2I%2FAAAAAAAAGb8%2FzVK3Ud_jcz8%2Fs800%2F%25E6%25B7%25BB%25E5%258A%25A0%25E9%25A1%25B5%25E9%259D%25A23.png.png&w=650)
如果没有"永久链接",就需要点击右上角的"屏幕选项",把"页面缩略名"打个勾.
![](http://oimageb7.ydstatic.com/image?url=http%3A%2F%2Flh3.ggpht.com%2F_IKN3boH2VZ0%2FSbS-rp4Mm4I%2FAAAAAAAAGcc%2FhntNFZNiGtw%2Fs800%2F%25E6%25B7%25BB%25E5%258A%25A0%25E9%25A1%25B5%25E9%259D%25A24.png.png&w=650)
在"页面缩略名"处填写"search"
即可
在右侧的"属性"-->"模板",处选择"Google 自定义搜索"为模板
![](http://oimagec5.ydstatic.com/image?url=http%3A%2F%2Flh5.ggpht.com%2F_IKN3boH2VZ0%2FSbS9gWoDy6I%2FAAAAAAAAGb0%2FKiKzhd55WEU%2Fs800%2F%25E6%25B7%25BB%25E5%258A%25A0%25E9%25A1%25B5%25E9%259D%25A22.png.png&w=650)
然后点击"发布"...
第二步:去google自定义搜索引擎创建自定义搜索引擎...![](http://oimagea6.ydstatic.com/image?url=http%3A%2F%2Flh4.ggpht.com%2F_IKN3boH2VZ0%2FSbSpjts1A_I%2FAAAAAAAAGVs%2FODZmVsS36qE%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E.png.png&w=650)
![](http://oimagea1.ydstatic.com/image?url=http%3A%2F%2Flh4.ggpht.com%2F_IKN3boH2VZ0%2FSbSrm1lwruI%2FAAAAAAAAGWM%2F7DX1qssu2a0%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E1.png.png&w=650)
设置您的网址格式单个网页:指定 www.mysite.com/mypage.html 仅会包含 www.mysite.com 上的 mypage.html 网页。
整个网站:指定 www.mysite.com/* 时会包含位于 www.mysite.com 的所有网页。
网站的一部分:可以使用通配符格式来指定仅包含网站的特定部分。例如,www.mysite.com/*about* 仅包含位于 www.mysite.com 且名称中含有 about 的文件。
整个域: 也可以使用 *.mydomain.com 来指定整个域。如果您指定 mydomain.com,我们会自动将它转换为 *.mydomain.com/*。如果您不希望这样,可以在控制面板中将其复原。 ![](http://oimageb4.ydstatic.com/image?url=http%3A%2F%2Flh3.ggpht.com%2F_IKN3boH2VZ0%2FSbSrnXfFonI%2FAAAAAAAAGWU%2F9bK3MpSCZu8%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E2.png.png&w=650)
![](http://oimagec6.ydstatic.com/image?url=http%3A%2F%2Flh3.ggpht.com%2F_IKN3boH2VZ0%2FSbSwg1BL2dI%2FAAAAAAAAGW0%2F9tRcX83jSys%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E3.png.png&w=650)
第三步:选择刚才创建的google自定义搜索引擎名称的控制面板
![](http://oimagec8.ydstatic.com/image?url=http%3A%2F%2Flh4.ggpht.com%2F_IKN3boH2VZ0%2FSbSzEd8i16I%2FAAAAAAAAGXU%2FdW0ZZ0ZlcAA%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E-%25E6%258E%25A7%25E5%2588%25B6%25E9%259D%25A2%25E6%259D%25BF.png.png&w=650)
然后选择左侧的"代码"
![](http://oimagec8.ydstatic.com/image?url=http%3A%2F%2Flh5.ggpht.com%2F_IKN3boH2VZ0%2FSbSztQCLDPI%2FAAAAAAAAGX0%2FpAoL2kpEOj0%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E-%25E4%25BB%25A3%25E7%25A0%2581.png.png&w=650)
选择搜索结果托管选项.....选择"在您的网站上托管搜索结果:iframe".在"显示搜索结果的网址"处填写http://zarva.org/search,这个网址就是显示搜索结果的.呆会我们需要用到的..."广告的位置",任选....
![](http://oimagea5.ydstatic.com/image?url=http%3A%2F%2Flh5.ggpht.com%2F_IKN3boH2VZ0%2FSbS0S9JtygI%2FAAAAAAAAGYU%2FX7eGO7Ckpt8%2Fs800%2Fgoogle%25E8%2587%25AA%25E5%25AE%259A%25E4%25B9%2589%25E6%2590%259C%25E7%25B4%25A2%25E5%25BC%2595%25E6%2593%258E-%25E4%25BB%25A3%25E7%25A0%25812.png.png&w=650)
修改googlesearch.php文件.把里边一些的关于文章评论,日志日期等内容删除,把"搜索结果代码"粘贴上去...
![](http://oimagea4.ydstatic.com/image?url=http%3A%2F%2Flh5.ggpht.com%2F_IKN3boH2VZ0%2FSbS7zOSMBeI%2FAAAAAAAAGa0%2FG4rsMsHRcHM%2Fs800%2Fgoogle_search.png.png&w=650)
第四步:
把主题里边默认的WordPress搜索框代码,以下是WordPress自带默Default认主题搜索框代码
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<label class="hidden" for="s"><?php _e('Search for:', 'kubrick'); ?></label>
<div><input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php _e('Search', 'kubrick'); ?>" />
</div>
</form>
找到<form开头,以/form>结束的部分用google自定义搜索引擎的"搜索框代码"代替....
![](http://oimagea4.ydstatic.com/image?url=http%3A%2F%2Flh5.ggpht.com%2F_IKN3boH2VZ0%2FSbTCyFzIpJI%2FAAAAAAAAGdc%2F7uFZElkrZmE%2Fs800%2F%25E6%25B7%25BB%25E5%258A%25A0%25E9%25A1%25B5%25E9%259D%25A26.png.png&w=650)
第五步:调整搜索框的样式...根据不同主题,调整不一样...就不说了....
第六步:进google自定义搜索引擎,选择控制面板--"外观"...可以修改搜索结果的外观....
第七步:进google自定义搜索引擎,选择控制面板--"赚钱"...把 Google 自定义搜索帐户目前与 AdSense id 相联...
效果请看本站右上角:
![](http://oimagec1.ydstatic.com/image?url=http%3A%2F%2Flh6.ggpht.com%2F_IKN3boH2VZ0%2FSbTHYiV_3lI%2FAAAAAAAAGek%2FXPNIly3kGW8%2Fs800%2Fgoogle.png.png&w=650)
转载原创文章请注明,转载自: 【朝华夕拾】 [http]