2007-07
31

在Wordpress中加入Google AJAX Search

这两天在为博客添加 Google 搜索功能的时候了解到了 Google AJAX Search ,听闻其功能很强大,于是马上 google 了一下,学习怎样加入到 wordpress 中。

在使用过程中参考了徘徊在玻璃之城的文章Google AJAX Search 使用简介,成功地将 Google AJAX Search加入到了我的 blog 中。下面给大家共享一下具体怎样做:(更新:由于 Google Ajax 搜索代码很多,比较拖速度,故本站暂停使用。本文介绍的方法仍然有效。)

首先你要做的是去 Google 的网站申请一个 Google AJAX Search API ,点击左下角的确认框,并且输入你的 blog 地址后,你会得到一个长长的 Key 。

然后把如下代码加入到你的 header.php 的 <head> 和 </head> 之间。

<script src=http://www.google.com/uds/api?file=uds.js&v=1.0&key=请在此处填写你的key type=text/javascript></script>
<script language=Javascript type=text/javascript>//<![CDATA[
function OnLoad() {
//
create a search control
var searchControl = new GSearchControl();
searchControl.setLinkTarget(GSearch.LINK_TARGET_SELF); //可选项,如果删除此行,搜索结果将在新页中打开
searchControl.setResultSetSize(GSearch.LARGE_RESULTSET); //可选项,如果删除此行,搜索结果将从10条变为4

// create a draw options object so that we
//
can position the search form root
var options = new GdrawOptions();
options.setSearchFormRoot(document.getElementById(searchForm));
options.setDrawMode(GSearchControl.DRAW_MODE_TABBED);

var siteSearch = new GwebSearch();
siteSearch.setUserDefinedLabel(填入你的网站标签);
siteSearch.setUserDefinedClassSuffix(siteSearch);
siteSearch.setSiteRestriction(填入你的blog网址);
searchControl.addSearcher(siteSearch);

// standard, unrestricted web search
searchControl.addSearcher(new GwebSearch());

searchControl.draw(document.getElementById(searchResults), options);
}
GSearch.setOnLoadCallback(OnLoad);
//]]
>
</script>

几个需要修改的地方已经在代码中说明。

接下来就看你需要什么样的显示方式了,你可以选择把搜索栏和搜索结果分开显示(就像我的一样),或者在一起显示。

  • 分开显示:

在你需要显示搜索结果的地方(如 index.php 或 single.php 中)加入如下代码(我放在了 <div id=”content”> 之后):

<div id=searchResults/></div>

然后在你需要显示搜索栏的地方加入如下代码(我放在了 sidebar.php 中):

<div id=searchForm></div>

  • 一起显示:

在你需要显示搜索栏和结果的地方加入如下代码:

<div id=searchResults/></div>

注意:经过我的测试,把搜索栏和搜索结果一起显示不需要 <div id=”searchForm”></div> ,在 <div id=”searchResults”/></div> 处会显示搜索栏和搜索结果。

最后,再把搜索栏和搜索结果的 CSS 样式加入你的 style.css 中,然后按照你自己的风格修改一下,就大功告成了。CSS 代码如下(需要修改的地方已经在代码中说明):

/** Copyright 2005 Google Inc. All rights reserved. */

/* the GSearchControl CSS Classes
* .gsc-control :主显示框
*/
.gsc-control {
width: 98%;
}

.gsc-control div {
position: static;
}

/* control inputs
* .gsc-search-box : 搜索栏大小
* .gsc-input : the text input area
* .gsc-keeper : the save link below savable results
*/
form.gsc-search-box {
width: 96%;
}

/*
* This table contains the input element as well as the search button
* Note that the search button column is fixed width, designed to hold the
* button divs background image
*/
table.gsc-search-box {
width : 100%;
margin-bottom : 2px;
margin-top : 5px;
margin-left: -6px;
}

td.gsc-search-button {
width : 1%;
}

td.gsc-clear-button {
width : 14px;
}

/**
* undo common generic table rules
* that tend to impact branding
*/
table.gsc-branding td,
table.gsc-branding {
margin: 0 0 0 0;
padding: 0 0 0 0;
border : none;
}

table.gsc-branding {
border-style : none;
border-width : 0px;
border-spacing : 0px 0px;
width : 100%;
}

td.gsc-branding-text {
vertical-align : top;
}

td.gsc-branding-text div.gsc-branding-text {
padding-bottom : 2px;
text-align : right;
color : #676767;
font-size : 11px;
margin-right : 2px;
}

td.gsc-branding-img-noclear {
width : 51px;
vertical-align : bottom;
}

td.gsc-branding-img {
width : 60px;
vertical-align : bottom;
}

input.gsc-search-button {
margin-left : 4px;
}

div.gsc-clear-button {
display : inline;
text-align : right;
margin-left : 4px;
margin-right : 4px;
padding-left : 10px;
background-repeat: no-repeat;
background-position: center center;
background-image: url(’http://www.google.com/uds/css/clear.gif’);
cursor : pointer;
}

/*
* Given that this is sitting in a variable width tabel cell, the idea is
* for it to consume the entire cell. The adjacent cell contains the search
* button and that is a fixed width cell.
*/
input.gsc-input {
padding-left : 2px;
border-style : solid;
border-width : 1px;
border-color : #BCCDF0;
width : 99%;
}

/* tabbed mode of search control
* .gsc-tabsArea : the box containing all of the tabs
* .gsc-tabsAreaInvisible : same as above, but this is the state when search has been cleared
* .gsc-tabHeader : an individual tab
* .gsc-tabHeader.gsc-tabhActive : the active tab
* .gsc-tabHeader.gsc-tabhInactive : an inactive tab
* .gsc-tabData : the data area/box containg results and header data for each tab
* .gsc-tabData.gsc-tabdActive : the data area for the active tab
* .gsc-tabData.gsc-tabdInactive : the data area for inactive tabs
*/
.gsc-tabsArea {
clear: both;
margin-top: 6px;
}

.gsc-tabsAreaInvisible {
display : none;
}

.gsc-tabHeader {
display: inline;
cursor: pointer;
display: inline;
padding: 2px 10px !important;
border: 1px solid #999; /*可修改搜索结果标题栏的边框颜色*/
border-bottom: none;
margin-bottom: 0;
margin-right: -6px; /*不要修改*/
margin-left: 10px; /*不要修改*/
}

.gsc-tabHeader.gsc-tabhActive {
background: #f3fce6; /*正在显示的搜索结果标题栏的背景*/
color: #0C72A2; /*正在显示的搜索结果标题栏的字体颜色*/

}

.gsc-tabHeader.gsc-tabhInactive {

}

.gsc-tabData.gsc-tabdActive {
display: block;
border: 1px solid #999; /*搜索结果显示栏的边框颜色*/
padding:10px;
background: #f3fce6; /*搜索结果显示栏的背景颜色*/
margin-bottom:10px; /*搜索结果显示栏内文字字体*/
font-size:14px;
}

/*此代码只对IE6适用*/
* html .gsc-tabData.gsc-tabdActive {
display: block;
border: 1px solid #999; /*搜索结果显示栏的边框颜色*/
padding:10px;
background: #f3fce6; /*搜索结果显示栏的背景颜色*/
margin-bottom:10px; /*搜索结果显示栏内文字字体*/
font-size:14px;
margin-top:1px; /*不要更改,保证tab显示效果和firefox一致*/
}

/*此代码只对IE7适用*/
*+ html .gsc-tabData.gsc-tabdActive {
display: block;
border: 1px solid #999; /*搜索结果显示栏的边框颜色*/
padding:10px;
background: #f3fce6; /*搜索结果显示栏的背景颜色*/
margin-bottom:10px; /*搜索结果显示栏内文字字体*/
font-size:14px;
margin-top:1px; /*不要更改,保证tab显示效果和firefox一致*/
}

.gsc-tabData.gsc-tabdInactive {
display: none;
}

/* tab specific results header supression
* - no twiddle, tabbed mode runs in full expand mode
* - no title
* - no stats
*/
.gsc-tabData .gsc-resultsHeader .gsc-title {
display: none;
}

.gsc-tabData .gsc-resultsHeader .gsc-stats {
display: none;
}

.gsc-tabData .gsc-resultsHeader .gsc-results-selector {
display : none;
}

/* the results for each section
* .gsc-resultsbox-{visible,invisible} : a complete-collection of results including headers
* .gsc-results : the collection of results for a given searcher
* .gsc-result : a generic result within the control. each result has this class, as well as .gsc-xxxResult where xxx is web, image, local, blog, etc.
*/

.gsc-resultsbox-visible {
display : block;
}

.gsc-resultsbox-invisible {
display : none;
}

.gsc-results {
clear: both;
padding-bottom: 2px;
}

.gsc-result {
margin-bottom: 10px;
}

.gsc-result .gs-title {
height: 1.4em;
overflow: hidden;
}

/* specialized, result type specific, fine grained controls */
.gsc-result div.gs-watermark {
display: none;
}

/* Ads
*/
.gsc-results .gsc-result img.gs-ad-marker {
display: none;
}

/*** End of Control, Begin Results ***/

/* generic, cross cutting result style
* - in the form of .gs-result .gs-xxx where xxx is the generic style
* .gs-title : typically the first line of a result, typically a link, image results over ride this, since for image results, the image is the link
* .gs-divider : typically seperates results from ads
* .gs-visibleUrl : typically the last line of a result, displayed in green. sometimes a link (like in blog search)
* .gs-clusterUrl : for news, and other similar services, this is a cluster of additional results
* img.gs-image : an actial image in a result
* .gs-phone : a phone number
* .gs-address : an address (includes street, city, region, country)
* .gs-streetAddress : a street (including #)
* .gs-city : a city
* .gs-region : a region (zip code, area, etc.)
* .gs-country : a country
* .gs-snippet : snippetized content
* .gs-watermark : indicator that user selected this result
* .gs-metadata : generic metadata, e.g.,
* .gs-image-box : generic container for a results image (within a table)
* .gs-text-box : generic container for a results text content (within a table). Note that this class, and image-box are only used in video
*/
.gs-result .gs-title,
.gs-result .gs-title * {
color: #0C72A2; /*搜索结果内容标题栏颜色 */
font-weight: bold;
text-decoration: underline;
padding-bottom:5px;
}

.gs-divider {
padding-bottom: 8px;
text-align: center;
color: #676767;
}

.gs-result a.gs-visibleUrl,
.gs-result .gs-visibleUrl {
color: #789d47; /*搜索结果来源网站的颜色 */
text-decoration: none;
}

.gs-webResult div.gs-visibleUrl-long {
width : 100%;
overflow : hidden;
display : none;
}

2007-07
30

QQ空间也有 RSS

有很多朋友在使用 QQ空间,但是 QQ空间花哨的外表使它的速度让人不敢恭维,很早就想要是 QQ空间也有 RSS feed 多好,我就既能摆脱它的缓慢又不至于错过朋友的日志了。

可能是我火星了,到现在才知道QQ空间也支持 RSS ,今天在用抓虾的时候才注意到的。

Feed 地址:http://feeds.qzone.qq.com/cgi-bin/cgi_rss_out?uin=[你要订阅的 QQ 号码]

例如,你要订阅的 QQ空间的 QQ 号码是123456,那么它的 feed 地址就是:http://feeds.qzone.qq.com/cgi-bin/cgi_rss_out?uin=123456。

好了,现在终于不用再忍受 QQ空间那巨慢的速度了,可以在阅读器中阅读朋友的日志了。

2007-07
29

高校科研经费去了哪里?

刚看到一则新闻:某省份2006年度审计报告近日公布,对高校科研经费使用情况的审计发现,直接用于课题研究的费用开支仅占40.5%,而管理费用、人员经费等开支占近六成。在这次审计中调查发现,有些高校还在科研经费中报销应由个人承担的家庭电话费、交通费、学费、私家车保险费和维修费等。这次审计涉及该省的10所高校2003年立项的265个课题项目。结果应该算是比较客观、普遍的了。

在高校的科研项目中,实验室的各种软硬件的资金投入已经不及招待费、管理费、劳务费、办公用品、电话费等“次要”投入,这是一个令人思考的问题。每次说起科研水平的问题都会以“科研投入不足”为理由,试问这些科研项目管理人员,你们真的是在用这些投入搞科研吗?有多少钱进入了你们自己的腰包?

看来,首要解决的问题不是科研投入不足的问题,而是科研资金流向了哪里的问题。

2007-07
29

怎样在 Firefox 中打开 QQ 链接和邮箱

虽然现在很喜欢用小巧、简洁的 Gtalk,但是 QQ 的群众基础还是太深厚了,几乎所有的同学朋友都是人手至少一个,而且 QQ 还有一些 Gtalk 没有的功能(发图、传文件等),所以 QQ 目前还是我用的最多的即时通讯软件。

如果你也在用 QQ ,而且也是 Firefox 的忠实用户的话,你有没有遇到过这样的问题:朋友通过 QQ 发来的地址点击以后默认在 IE 中打开,点击 QQ 面板上的邮箱也是默认使用 IE 打开,即使是把 Firefox 设为默认浏览器也不行。经过查找,终于知道了解决办法。

代码:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\HTTP\shell]
@=”Firefox”

[HKEY_CLASSES_ROOT\HTTP\shell\Firefox]

[HKEY_CLASSES_ROOT\htmlfile\shell]
@=”Firefox”

[HKEY_CLASSES_ROOT\HTTP\shell\Firefox\command]
@=”D:\\Program Files\\Mozilla Firefox\\FIREFOX.EXE -url \”%1\”"

[HKEY_CLASSES_ROOT\htmlfile\shell\open\command]
@=”D:\\Program Files\\Mozilla Firefox\\FIREFOX.EXE -url \”%1\”"

[HKEY_CLASSES_ROOT\htmlfile\shell\Firefox\command]
@=”D:\\Program Files\\Mozilla Firefox\\FIREFOX.EXE -url \”%1\”"

将以上代码复制到记事本,保存为 .reg 文件,导入注册表即可。注意:代码中红色部分为我的 Firefox 的安装目录,请根据你自己的安装目录修改。

若要恢复为注册表原始设置,将下列代码以同样方式执行即可,并把 IE 设为默认浏览器。

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\HTTP\shell]
@=”open”

[HKEY_CLASSES_ROOT\htmlfile\shell]
@=”open”

希望本文对 Firefox 用户有所帮助。

2007-07
27

有关博客的一些概念介绍

有很多朋友对博客相关的一些概念还不是很清楚,我觉得有必要写一下做一个介绍。我只是一个刚刚开始博客的新手,有什么理解错误的地方请高手指教。也欢迎大家和我讨论。

什么是博客?

Blog是Weblog的简写,中文含义为“网络日志”,而博客(Blogger)就是写Blog的人。实际上个人博客网站就是网民们通过互联网发表各种思想的虚拟场所,浏览博客的用户可以阅读博客中的文章,并发表评论,达到共享、交流的。本站就是一个典型的个人博客。

什么是RSS?

RSS(Really Simple Syndication),它本身的英文全称比较晦涩难懂,也没有很明确的中文翻译,我就不再过多解释,只想通过通俗的语言解释清楚它到底是做什么用的。RSS是一种技术,它的用途就是进行网上新闻、博客和其他Web内容的数据交换。通过RSS,你不需要浏览页面就可以获得其中的信息。

怎样才可以通过RSS获得想要的信息?如何订阅?

首先你需要订阅一个提供RSS服务的站点(例如订阅本站),然后还要有一个RSS阅读器(新手推荐使用抓虾鲜果,简捷易用,见本站右边侧栏“快捷订阅”)。打个比方来说,你在邮局订阅了一份报纸,这份报纸 就是你要通过RSS获得的信息,而RSS阅读器,就是你的报箱。当有新报纸的时候,邮递员会自动把报纸放入你的报箱,你只需要打开报箱看报纸就行了,不必关心怎样获得报纸,因为你已经订阅了它。RSS阅读器就是这样,当你订阅的网站内容更新时,RSS阅读器就会自动接收,把最新的信息接收到你的阅读器中,你只需要打开浏览即可。现在网络上的RSS资源已经非常丰富,只要看到网站上有rss_xml.jpg 标志,就说明该网站提供RSS服务,你就可以订阅它到你的阅读器。在你使用了某个阅读器订阅了一些东西之后,你就会明白RSS是怎么回事了。

什么是Feed?

同RSS一样,feed也很难用以一个中文词语来表达,feed是要和RSS一起来理解的。我本人对feed的理解是“信息源”。它就是你要通过RSS订阅的信息的种子。拿上边举的那个例子来说,feed就相当于报纸的订阅点。

我每发现一个好的博客,第一件事就是去页面上找feed,然后添加到我的阅读器,之后我就可以放心的关闭窗口,而不需要把这个站点加入收藏夹,因为我已经有了它的feed,它以后的所有更新将会自动发送到我的阅读器。Feedburner就是一个著名的提供feed烧制服务的站点,它可以把你的网站烧制成feed,提供给其他用户订阅。国内的Feedsky也提供这个服务。

现在你明白我的右侧栏的“快捷订阅”了吧?还不明白?那就订阅一个试试看。

什么是SEO?

SEO(Search Engine Optimization),中文含义为“搜索引擎优化”。SEO的主要工作是通过了解各类搜索引擎如何抓取互联网页面、如何进行索引以及如何确定其对某一特定关键词的搜索结果排名等技术,来对网页进行相关的优化,使其提高搜索引擎排名,从而提高网站访问量,最终提升网站的销售能力或宣传能力。

SEO是一门很深奥的学问,我对它的认识也仅仅停留在“知道是什么意思”的水平,以后慢慢研究。

什么是PingBack?

如果你很熟悉电脑,你一定知道什么是ping命令吧?Pingback可以分开理解,ping back,即ping回溯。Pingback是网络中常用的用来通知文章被引用情况的一种方法。这个方法使得Web作者可以追踪什麽人连结至他的文章。

什么是TrackBack?

引用月光的解释:)

Traceback Ping在blog系统中广泛使用,简单说来,Trackback是网站与网站之间互相通告的一种方法。例如,当你读了一篇日志,想对此写下自己的感想,您可以把新的日志内容写到自己的博客上。然后向原来的那篇日志发送一个引用通告。通过这种办法,在原始文章的下面就留下了你自己博客中的日志的链接,这样对于同一个话题的讨论,可以不局限在一个博客中了。

Traceback在中国大部分被翻译做“引用通告”,因此带来一个很大的误解,不少人将TrackBack理解为引用地址,我经常收到一些莫名其妙的Traceback,点过去一看,原来只是转载我的文章而已,这显然是错误地理解和使用了TrackBack,将其误以为是“引用”的含义了,事实上TrackBack不是这么使用的。

举个例子来说明一下。比如你在我的月光博客中看了一篇感兴趣的文章,对这篇文章你自己有一些看法,但是如果你写的文字较多的话,通常会超过评论字数的限制,这时候你可以在自己的Blog中写下看法,这样带来的好处是字数不受限制,而且还利于以后维护,但是你怎么告诉我你写了这个评论呢?如果没有Traceback的话,你只能将你的链接 URL地址回复在评论上,但有了Trackback Ping,就不再需要这样做了,你只要通过Trackback将你的文章信息Ping过来,我的Blog系统会自动接收来自其他Blog网站 Trackback Ping,并将其发布到文章中,这才是Trackback的正确用法,可惜国内大多数Blogger还没有形成正确使用Trackback的习惯。