<div id="newComments">
<noscript>failed!<br/>Javascript not supported here!</noscript>
</div>
<script>
var nCommentStartIndex = 1;
var nCommentShow = 6;
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>更改标题为"最新评论"。
保存。
2009-07-21
如何为Blogger添加最新评论
如何为Blogger添加最新评论
2009-07-21T21:24:00+08:00
Joe
信息||Info|