自從舊文《在Blogger加入最新回應Recent Coments》貼出,網友們都想知道怎樣設置像拉比一樣的‘最新回應’版塊。
現在我就教大家如何設置它。
方法如下:
1. 進入你的Blogger,点选[Layout] → [Page Elements] → [Add a Gadget] → [Html/JavaScript]
2. 把下面的code貼在其中。
<div id="newComments">
<noscript>failed!<br/>Javascript not supported here!</noscript>
</div>
<script>
var nCommentStartIndex = 1;
var nCommentShow = 8;
function showRecentComments(nIndex) {
if (!nIndex)
nIndex = nCommentStartIndex;
var sFeedURL = '/feeds/comments/summary?orderby=published&start-index='+nIndex+'&max-results='+(nCommentShow+1)+'&alt=json-in-script&callback=generateComments';
var script = document.createElement('script');
document.getElementById('newComments').innerHTML = 'Loading <blink>...</blink>';
script.setAttribute('src', sFeedURL);
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script);
}
function generateComments(json) {
function compareentry(a,b) {
order= Date.parse(a.published.$t.replace(/^(\d{4})-(\d{2})-(\d{2})T([0-9:]*)([.0-9]*)(.)(.*)$/, '$1/$2/$3 $4 GMT')) - Date.parse(b.published.$t.replace(/^(\d{4})-(\d{2})-(\d{2})T([0-9:]*)([.0-9]*)(.)(.*)$/, '$1/$2/$3 $4 GMT'));
return 0-order;
}
var sHTML = '<ul>';
var sortentry = json.feed.entry.sort(compareentry);
var nIndex = parseInt(json.feed.openSearch$startIndex.$t);
var nTotalComment = parseInt(json.feed.openSearch$totalResults.$t);
for (var i = 0, Comment; Comment = sortentry[i]; i++) {
if (i >= nCommentShow)
break;
var authorname = Comment.author[0].name.$t;
var title = Comment.title.$t.substr(0,30);
var j = 0;
while (j < Comment.link.length && Comment.link[j].rel != "alternate")
j++;
var link = Comment.link[j].href;
var timestamp = Comment.published.$t.substr(0,10);
sHTML += '<li><span class="item-title">'+authorname+': <a href="'+link+'">'+ title +'</a> - '+timestamp+'</span></li>';
}
sHTML += '</ul>';
sHTML += generateCommentLink(parseInt(json.feed.entry.length), nIndex, nTotalComment);
document.getElementById('newComments').innerHTML = sHTML;
}
function generateCommentLink(nFetch, nIndex, nTotalComment) {
var bOld = (nFetch > nCommentShow);
if (bOld) nFetch = nCommentShow;
var sResult = '<p align="right">Recent '+nIndex+'-'+(nIndex+nFetch-1)+', total: '+nTotalComment+'. ';
if (nIndex > nCommentStartIndex)
sResult += '<a href="javascript:showRecentComments('+(nIndex-nCommentShow)+');" title="Newer Comments"><<</a> ';
if (bOld)
sResult += '<a href="javascript:showRecentComments('+(nIndex+nCommentShow)+');" title="Older Comments">>></a>';
sResult += '</p>';
return sResult;
}
</script>
<script language="javascript">showRecentComments();</script>
3. 按Save即完成。
code中紅色的那兩行一樣視個人狀況調整,範例是從最新的「第一個回應」、每一頁顯示「八篇回應」,如果不喜歡的話,那就自己修改囉!
8 回應:
真的很好用~謝謝你~
可以加上"文章名字"嗎?
比如說是留言在哪一篇...^^
哇~~我等你这一篇很久了叻~~
真是谢谢你!^^
又来塞钱进我袋,放工回家慢慢研究先,先谢过啦!
这很好用
这个我好像都在用着了~呵呵 XD
下次教如何pOST放密码 好吗?
楼上说的放密码我也很想学呢^^
谢谢你,我抱走了...
張貼留言
回應時可以使用HTML標記如:
<b>粗體</b>, <i>斜體</i>, <a href = '網址'>網址名稱</a>