转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> 搜索优化 >> 正文
[组图]将DISCUZ提供的Google搜索转化为自己的站内检索的方法         ★★★

DISCUZ提供的Google搜索转化为自己的站内检索的方法

将DISCUZ提供的Google搜索转化为自己的站内检索的方法
作者:闵涛 文章来源:闵涛的学习笔记 点击数:2148 更新时间:2008/5/30 0:03:35

DISCUZ提供的Google搜索转化为自己的站内检索

DZ提供了google搜索的功能,您需要在后台的扩展设置--google搜索里面开启它,您就可以在首页看到google搜索的输入框,
式样可参见:http://www.stupc.org/bbs
每个站长都可以自主申请通过Google AdSense for Search 为网站带来收益,申请后可以将Google AdSense for Search的代码直接放到论坛上面,但是这样做没有象DISCUZ整合得那么好。。。
^_^,个人觉得美观还是挺重要的。
首先我们来分析一下google给我们提供的搜索代码:
引用:
<!-- SiteSearch Google -->
<form method="get" action="http://www.google.cn/custom" target="google_window">
<table border="0" bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="/Article/UploadFiles/200805/20080530000815232.gif" border="0" alt="Google" align="middle"></img></a>
</td>
<td nowrap="nowrap">
<input type="hidden" name="domains" value="www.stupc.org"></input>
<label for="sbi" style="display: none">输入您的搜索字词</label>
<input type="text" name="q" size="31" maxlength="255" value="" id="sbi"></input>
<label for="sbb" style="display: none">提交搜索表单</label>
<input type="submit" name="sa" value="搜索" id="sbb"></input>
</td></tr>
<tr>
<td> </td>
<td nowrap="nowrap">
<table>
<tr>
<td>
<input type="radio" name="sitesearch" value="" checked id="ss0"></input>
<label for="ss0" title="搜索网络"><font size="-1" color="black">Web</font></label></td>
<td>
<input type="radio" name="sitesearch" value="www.stupc.org" id="ss1"></input>
<label for="ss1" title="搜索 www.stupc.org"><font size="-1" color="black">www.stupc.org</font></label></td>
</tr>
</table>
<input type="hidden" name="client" value="pub-5156024908578575"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="GB2312"></input>
<input type="hidden" name="oe" value="GB2312"></input>
<input type="hidden" name="cof" value="GALT:#9A2C06;GL:1;DIV:#33FFFF;VLC:D03500;AH:center;BGC:99CCFF;LBGC:CCE5F9;ALC:440066;LC:440066;T:336699;GFNT:223472;GIMP:223472;LH:50;LW:124;L:/Article/UploadFiles/200805/20080530000816551.gif;S:http://;FORID:1"></input>
<input type="hidden" name="hl" value="zh-CN"></input>
</td></tr></table>
</form>
<!-- SiteSearch Google -->
再来看看DISCUZ里面嵌套的代码:
我是通过分析discuz.htm文件(路径:../templates/default/discuz.htm)
里面有一段是这么写的:
引用:
        <!--{if !empty($google) && ($google & 1)}-->
                <div id="headsearch" style="clear: both">
                <script type="text/javascript" src="forumdata/cache/google_var.js"></script>
                <script type="text/javascript" src="include/javascript/google.js"></script>
                </div>
        <!--{/if}-->
IF是判断语句,当你开启google的时候会自动屏蔽。找到google_var.js和google.js文件
google_var.js里面内容如下:
复制内容到剪贴板
代码:
var google_host="www.stupc.org";var google_charset="gbk";var google_hl="zh-CN";var google_lr="lang_zh-CN";
明显没有用。我们接着看google.js里面的内容:
复制内容到剪贴板
代码:
document.writeln('<script type="text/javascript">');
document.writeln('function validate_google(theform) {');
document.writeln('        if(theform.site.value == 1) {');
document.writeln('                theform.q.value = \'site:' + google_host + ' \' + theform.q.value;');
document.writeln('        }');
document.writeln('}');
document.writeln('function submitFormWithChannel(channelname) {');
document.writeln('        document.gform.channel.value=channelname;');
document.writeln('        document.gform.submit();');
document.writeln('        return;');
document.writeln('}');
document.writeln('</script>');
document.writeln('<form name="gform" id="gform" method="get" action="http://www.google.cn/search?" target="_blank" onSubmit="validate_google(this);">');
document.writeln('<input type="hidden" name="client" value="aff-discuz" />');
document.writeln('<input type="hidden" name="ie" value="' + google_charset + '" />');
document.writeln('<input type="hidden" name="oe" value="UTF-8" />');
document.writeln('<input type="hidden" name="hl" value="' + google_hl + '" />');
document.writeln('<input type="hidden" name="lr" value="' + google_lr + '" />');
document.writeln('<input type="hidden" name="channel" value="search" />');
document.write('<div onclick="javascript:submitFormWithChannel(\'logo\')" style="cursor:pointer;float: left;width:70px;height:23px;background: url(images/common/Google_small.png) !important;background: none;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/common/Google_small.png\', sizingMethod=\'scale\')"><img src="images/common/none.gif" border="0" alt="Google" /></div>');
document.writeln('&nbsp;&nbsp;<input type="text" size="10" name="q" id="q" maxlength="255" value=""></input>');
document.writeln('<select name="site">');
document.writeln('<option value="0">网页搜索</option>');
document.writeln('<option value="1">站内搜索</option>');
document.writeln('</select>');
document.writeln('&nbsp;<button type="submit" name="sa" value="true">搜索</button>');
document.writeln('</form>');
仔细对比:大家会发现,我标红的代码再hidden状态的几个参数,其中包含了discuz的帐号,和我在google adsence上的帐号
GOOGLE上面的代码片段
<input type="hidden" name="client" value="pub-5156024908578575"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="GB2312"></input>
<input type="hidden" name="oe" value="GB2312"></input>
<input type="hidden" name="cof" value="GALT:#9A2C06;GL:1;DIV:#33FFFF;VLC:D03500;AH:center;BGC:99CCFF;LBGC:CCE5F9;ALC:440066;LC:440066;T:336699;GFNT:223472;GIMP:223472;LH:50;LW:124;L:/Article/UploadFiles/200805/20080530000816551.gif;S:http://;FORID:1"></input>
<input type="hidden" name="hl" value="zh-CN"></input>

和以上这些代码对应的DIUCUZ代码写法:
document.writeln('<input type="hidden" name="client" value="aff-discuz" />');
document.writeln('<input type="hidden" name="ie" value="' + google_charset + '" />');
document.writeln('<input type="hidden" name="oe" value="UTF-8" />');
document.writeln('<input type="hidden" name="hl" value="' + google_hl + '" />');
document.writeln('<input type="hidden" name="lr" value="' + google_lr + '" />');
document.writeln('<input type="hidden" name="channel" value="search" />');

参数名称有:
client:google adsence帐号
forid:默认为1
cof:搜索之后回显的页面样式表,包括你在google adsence申请过程中设定的搜索之后出现的网页上方的logo和页面的颜色。但是用google的代码直接放在网站上搜索出现的页面有之前订制的样式,但是放到discuz中的代码中替换总是出不来订制的
ie:discuz的默认值为' + google_charset + ';google默认为GB2312
oe:网站编码,一般为UTF-8或者GB2312
hl:discuz的默认值为' + google_hl + ';google中我选择之后没有这个参数
lr:discuz的默认值为' + google_lr + ';google中我选择的也没有这个参数
channel:渠道
下面就是说到如何修改这个东西:
复制内容到剪贴板
代码:
document.writeln('<input type="hidden" name="client" value="aff-discuz" />');
将上面这句话替换成以下的形式:
复制内容到剪贴板
代码:
document.writeln('<input type="hidden" name="client" value="pub-5156024908578575" />');
document.writeln('<input type="hidden" name="forid" value="1"></input>');
document.writeln('<input type="hidden" name="cof" value="GALT:#9A2C06;GL:1;DIV:#33FFFF;VLC:D03500;AH:center;BGC:99CCFF;LBGC:CCE5F9;ALC:440066;LC:440066;T:336699;GFNT:223472;GIMP:223472;LH:50;LW:124;L:/Article/UploadFiles/200805/20080530000816551.gif;S:http://;FORID:1"></input>');
自己修改上面涉及到的帐号和对应的cof数值。。。
下面我们来看看点击搜索之后ie上显示的字符串的区别:
DISCUZ的默认代码搜索之后:
复制内容到剪贴板
代码:
http://www.google.cn/search?client=aff-discuz&ie=gbk&oe=UTF-8&hl=zh-CN&lr=lang_zh-CN&channel=search&q=%BD%D3%BF%DA&site=0&sa=%CB%D1%CB%F7
修改成自己帐号之后搜索出现的字符串:
复制内容到剪贴板
代码:
/Article/UploadFiles/200805/20080530000816754.gif%3BS%3Ahttp%3A%2F%2F%3BFORID%3A1&ie=gbk&oe=UTF-8&hl=zh-CN&lr=lang_zh-CN&channel=search&q=%BF%F2%BC%DC&site=0&sa=%CB%D1%CB%F7
呵呵,另外放一个小技巧在这里:
如何把Google搜索下拉菜单“站内搜索”设置为默认:
相信很多站长都需要这样的设置,其实很简单:
用记事本打开 google.js ,找到如下代码:
复制内容到剪贴板
代码:
document.writeln('<option value="0">网页搜索</option>');
document.writeln('<option value="1">站内搜索</option>');
把这个两行换一下位置,显示如下:
复制内容到剪贴板
代码:
document.writeln('<option value="1">站内搜索</option>');
document.writeln('<option value="0">网页搜索</option>');
这样就完成了,希望能帮到大家哦。。。

[搜索优化]敏韬网:Google的PageRank(PR)详解、定义解析  [精彩网文]励志人物简介:李开复
[精彩网文]李开复:再见,谷歌  [Web开发]loop调用discuz大全
[Web开发]Discuz!如何修改Email验证有效性时长  [办公软件]利用幻灯片搜索器高效、快速批量复制另外一个演示…
[Web开发]利用Ajax技术实现在线歌词搜索功能  [网页制作]什么是网站PR(PageRank)值,PR值的大小与搜索引擎…
[网页制作]大众都在使用的各大搜索引擎列表  [网页制作]Google搜索引擎创始人谢尔盖-布林、拉里-佩奇介绍
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台