Lần trước mình giới thiệu cho các bạn cách hiện thị các comment gần đây dùng File JS nhiều bạn không thích vì nó phụ thuộc vào Hotsting riêng và giao diện nhìn không được bắt mắt cho lắm hôm nay mình xẽ giới thiệu cho các bạn code khoogn sử dụng File JS mà tất cả là CSS giao diện nhìn cũng đẹp
Code của thủ thuật
<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 href="' + ctlink + '">(xem thêm...)</a>');
}
}
document.write('</li>');

}
</script>
<script src="http://namkna.blogspot.com/feeds/comments/default?alt=json-in-script&callback=showrecentcomments">
</script></ul>
trong đó
+ i<10 là số comment hiển thị trên blog , ở đây tôi cho hiển thị 10 comment .Nếu muốn hiển thị nhiều hơn thì các bạn cứ chỉnh lại con số mà thôi .
+http://namkna.blogspot.com/feeds/comments/default?alt=json-in-script&callback=showrecentcomments sửa lại thành tên blog của bạn .
Lưu ý , thủ thuật này chỉ áp dụng được với Google Blogger .
- Các bạn có thể xem Demo ở dưới đây
Chúc thành công!