最新回應的作法

最新回應的作法,是從Josh's Note
讓comments也能顯示文章標題修改來的




原本的排版我不喜歡,所以改了一下。
並傳到Google Page Creator

在Blogger後台的版面配置,開一個HTML/Javascript的 element,並插入下列語法

紅色部分為Blog的位址

<script>g_szBlogDomain='xxxxx.blogspot.com'; </script>
<script src="http://twpaddy.googlepages.com/rc.js"></script>

直接把上面那一段的語法貼上即可。

js檔的程式如下,需要的可以自己拿去改:

var g_szBlogDomain;
if (g_szBlogDomain==undefined) g_szBlogDomain='http://paddyfeel.blogspot.com';
document.write('<div id="divrc">下載中...</div>');
var g_szAuthorsLink=new Array();
var g_szTitle= new Array();
var g_szOrgLink = new Array();
var g_iIndex=0;
var g_iShowCount=5;
function a_comprc(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;
}
function a_rc(json)
{
g_szComments = json.feed.entry.sort(a_comprc);
}
function a_FindTitle(posts,orgLink)
{
var ret= orgLink;
for (var ii=0,post; post= posts.feed.entry[ii]; ii++)
{
if (post.link[0].href == orgLink)
{
ret= post.title.$t;
break;
}
}
return ret;
}
function a_FindIndex(posts,orgLink)
{
var ij=0;
for (ij=0; ij < g_iIndex; ij++)
{
if (orgLink==g_szOrgLink[ij])
return ij;
}
g_szOrgLink[ij]=orgLink;
g_szTitle[ij]= a_FindTitle(posts,orgLink);
g_szAuthorsLink[ij]='◎';
g_iIndex ++;
return ij;
}
function b_rc(posts)
{
var temp = "";
for (var i=0,comment; comment = g_szComments[i]; i++)
{

var content = comment.title.$t;
var link = comment.link[0].href;
var orgLink= link;
var link2 = link;
var iFind = link.indexOf('?');
if (iFind<0)
iFind = link.indexOf('#');
if (iFind>0)
orgLink = link.substring(0,iFind);
var index = a_FindIndex(posts,orgLink);
if (index>= g_iShowCount)
{
g_iIndex--;
break;
}
var auther= comment.author[0].name.$t;
var timestamp=comment.published.$t.substr(0,10) + ' ' +comment.published.$t.substr(11,5);


temp += '<div style="text-align:left;">' + auther + ':<a href="' + link2 + '" title="' + content + '">' + content.substring(0,12) + '</a></div>';
temp += '<div style="text-align:right;padding: 0px 0px 5px 0px;">Re: <a href="' + g_szOrgLink[index] + '">' + g_szTitle[index].substring(0,10) + '</a> </div>';
}
document.getElementById("divrc").innerHTML = temp;
}
document.write('<script src="http://' + g_szBlogDomain + '/feeds/comments/summary?alt=json-in-script&callback=a_rc"></script><script src="http://' + g_szBlogDomain + '/feeds/posts/summary?alt=json-in-script&callback=b_rc&max-results=99"></script>');

HEMiDEMi Technorati Del.icio.us MyShare個人書籤 Yahoo

張貼者:Paddy 於 下午2:10  

0 意見:

張貼留言