Hướng dẫn tạo widget (Nhận xét mới nhất) cho blog

Sau mỗi bài viết, khi khách truy cập vào có thể để lại lời nhận xét về bài viết hay những vấn đề thắc mắc đó. Nếu luôn phải tìm những lời nhận xét "Comments" đó thì thật vất vả. Vậy hãy tạo một widget thu thập những "Nhận xét mới nhất" nào.
Bạn hãy coppy đoạn code dưới và cho vào Widget "HTML/Javascrip" đặt bất cứ đâu trên blog:
<ul><script style="text/javascript">
function showrecentcomments(json) {
for (var i = 0; i < 10; i++) {
var entry = json.feed.entry[i];
var ctlink;

if (i == json.feed.entry.length) break;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'alternate') {
ctlink = entry.link[k].href;
break;
}
}
ctlink = ctlink.replace("#", "#comment-");
var ptlink = ctlink.split("#");
ptlink = ptlink[0];
var txtlink = ptlink.split("/");
txtlink = txtlink[5];
txtlink = txtlink.split(".html");
txtlink = txtlink[0];
var pttitle = txtlink.replace(/-/g," ");
pttitle = pttitle.link(ptlink);
if ("content" in entry) {
var comment = entry.content.$t;}
else
if ("summary" in entry) {
var comment = entry.summary.$t;}
else var comment = "";
var re = /<\S[^>]*>>/g;
comment = comment.replace(re, "");

document.write('<li>');
document.write('<a href="' + ctlink + '">' + entry.author[0].name.$t + '</a>');

document.write('<br/>');
if (comment.length < 100) {
document.write(comment);
}
else
{
comment = comment.substring(0, 100);
var quoteEnd = comment.lastIndexOf(" ");
comment = comment.substring(0, quoteEnd);
document.write(comment + '...<a target="_blank" href="' + ctlink + '">[[Đọc tiếp]]</a>');
}
}
document.write('</li>');

}
</script>
<script src="http://ITmod.blogspot.com/feeds/comments/default?alt=json-in-script&callback=showrecentcomments">
</script></ul>
Trong đó bạn hãy đổi dòng sau thành tên blog của bạn:
<script src="http://ITmod.blogspot.com/feeds/comments/default?alt=json-in-script&callback=showrecentcomments"></script>

Muốn hiện bao nhiêu comment bạn thay đổi số 10 thành số mà bạn muốn ở dòng code này:
for (var i = 0; i < 10; i++) {
* Lưu ý: Đoạn code này chỉ sử dụng riêng cho Blogger.com
Loading related posts...

1 Comment:

mmovn said...

chà...hôm nay vi vu mới gặp blog này...
xin chào bạn !
:D

Post a Comment

/
 
CopyRight 2008 - Admin ModestPC - Template by Blogger Team