2007年3月8日星期四

Blogger 实用 Hack 技巧总结之三

7.让某一元素只在首页或非首页显示
通过元素的title搜索到后,按需要加入下面红色代码。
<b:widget id='HTML1' locked='false' title='Recent Articles' type='HTML'>
<b:includable id='main'>

<b:if cond='data:blog.homepageUrl == data:blog.url'> /*只在首页显示*/
<b:if cond='data:blog.homepageUrl != data:blog.url'> /*不在首页显示*/

<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
<b:include name='quickedit'/>

</b:if>

</b:includable>
</b:widget>


8.高亮作者评论咖啡鱼原文
第一步,添加CSS:
.comment-body-author {
margin:0;
padding:20px 0 20px 40px;
}
.comment-body-author p {
font-size:100%;
margin:0 0 .2em 0;
color:#CC3300; /*字体颜色*/
text-decoration:bold; /*字体样式,默认加粗*/
}

第二步:找到以下类似代码,全部替换:
<a expr:name='"comment-" + data:comment.id'/>
<b:if cond='data:comment.authorUrl'>
<a expr:href='data:comment.authorUrl' rel='nofollow'><data:comment.author/></a>
<b:else/>
<data:comment.author/>
</b:if>
<data:commentPostedByMsg/>
</dt>
<b:if cond='data:comment.author == data:post.author'> <dd class='comment-body-author'> <p><data:comment.body/></p> </dd> <b:else/>
<dd class='comment-body'>
<b:if cond='data:comment.isDeleted'>
<span class='deleted-comment'><data:comment.body/></span>
<b:else/>
<p><data:comment.body/></p>
</b:if>
</dd>
</b:if>
<dd class='comment-footer'>


9.具有按钮效果的链接咖啡鱼原文
想在博客的某一部分加上这个效果,可以搜索a:hover,在属性里增加position: relative; top: 1px; left: 1px;。如:
a:hover {
text-decoration: underline;
color: #0094F0;
position: relative; top: 1px; left: 1px;
}

如果只想单独定义某个链接,请查看原文

10.收缩展开文章原文
原文已经介绍得很清楚,在这里不帖出原代码,需要注意的是,这一语句<script type='text/javascript' src='http://jrchen82.googlepages.com/hackosphere.js' />,必须粘在</head>前方。
这一语句:
<p><a expr:onclick='"javascript:showFull(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>Read More...</a></p>
可以改为下面的形式,增加一小图片,
<p><a expr:onclick='"javascript:showFull(\"post-" + data:post.id + "\");"' href='javascript:void(0);'>显示全文<img border='0' src='http://jrchen82.googlepages.com/readmore.gif'/></a></p>
同理,
<p><a expr:onclick='"javascript:hideFull(\"post-" + data:post.id + "\");"'href='javascript:void(0);'>Summary only...</a></p>
可以改为:
<p><a expr:onclick='"javascript:hideFull(\"post-" + data:post.id + "\");"'href='javascript:void(0);'>显示摘要<img border='0'
src='http://jrchen82.googlepages.com/summary.gif'/></a></p>

11.添回到页首,回到帖子标题链接
找到下面的代码,并添加红色部分。如果使用了上一个HACK,可略过此步
<b:includable id='post' var='post'>
<div class='post' expr:id='"post-" + data:post.id' >

把下面代码粘在<b:include data='post' name='postQuickEdit'/>之后或任何你想让它出现的地方。
<a expr:onclick='"javascript:document.getElementById(\"post-" + data:post.id + "\").scrollIntoView(true);"' href='javascript:void(0);' title='Scroll to top of post'>回到开头↑</a>
<!-- to top of page and top of blog -->
<a href='javascript:scroll(0,0)' title='Scroll to top of this page'>回到页首↑</a>

同样这里可以仿照上一个HACK,加入小图标。

12.显示相关文章(原文
第一步:选中“扩展窗口小部件模板”,把下面代码放在</head>正前方
<script type="text/javascript">
//<![CDATA[
var relatedTitles = new Array();
var relatedTitlesNum = 0;
var relatedUrls = new Array();
function related_results_labels(json) {
for (var i = 0; i < json.feed.entry.length; i++) {
var entry = json.feed.entry[i];
relatedTitles[relatedTitlesNum] = entry.title.$t;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
relatedUrls[relatedTitlesNum] = entry.link[k].href;
relatedTitlesNum++;
break;
}
}
}
}
function removeRelatedDuplicates() {
var tmp = new Array(0);
var tmp2 = new Array(0);
for(var i = 0; i < relatedUrls.length; i++) {
if(!contains(tmp, relatedUrls[i])) {
tmp.length += 1;
tmp[tmp.length - 1] = relatedUrls[i];
tmp2.length += 1;
tmp2[tmp2.length - 1] = relatedTitles[i];
}
}
relatedTitles = tmp2;
relatedUrls = tmp;
}
function contains(a, e) {
for(var j = 0; j < a.length; j++) if (a[j]==e) return true;
return false;
}
function printRelatedLabels() {
var r = Math.floor((relatedTitles.length - 1) * Math.random());
var i = 0;
document.write('<ul>');
while (i < relatedTitles.length && i < 20) {
document.write('<li><a href="' + relatedUrls[r] + '">' + relatedTitles[r] + '</a></li>');
if (r < relatedTitles.length - 1) {
r++;
} else {
r = 0;
}
i++;
}
document.write('</ul>');
}
//]]>
</script>

第二步:找到以下代码:
<b:if cond='data:post.labels'>
<data:postLabelsLabel/>
<b:loop values='data:post.labels' var='label'>
<a expr:href='data:label.url' rel='tag'><data:label.name/></a><b:if cond='data:label.isLast != "true"'>,</b:if>
</b:loop>
</b:if>

更改为:
<b:if cond='data:post.labels'>
<data:postLabelsLabel/>
<b:loop values='data:post.labels' var='label'>
<a expr:href='data:label.url' rel='tag'><data:label.name/></a><b:if cond='data:label.isLast != "true"'>,</b:if>
<b:if cond='data:blog.pageType == "item"'>
<script expr:src='"/feeds/posts/default/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels&max-results=10"' type='text/javascript'/>
</b:if>
</b:loop>
</b:if>

第三步:保存,跳转至页面元素,添加一个HTML/Javascript元素,命名为“相关文章”,放入以下代码:
<script type="text/javascript">
removeRelatedDuplicates();
printRelatedLabels();
</script>

第四步:回到Html编辑,选中“扩展窗口小部件模板”,查找“相关文章”,把该部分加入红色代码:
<b:widget id='HTML ' locked='false' title='相关文章' type='HTML'>
<b:includable id='main'>
<b:if cond='data:blog.pageType == "item"'>
<!-- only display title if it's non-empty -->
<b:if cond='data:title != ""'>
<h2 class='title'><data:title/></h2>
</b:if>
<div class='widget-content'>
<data:content/>
</div>
<b:include name='quickedit'/>
</b:if>
</b:includable>
</b:widget>

绿色部分为自定义项目。

0 评论: