Chat
Danh mục
Tạo tiện ích Bài viết Hot – Top Comments

Tạo tiện ích Bài viết Hot – Top Comments

Số lượng:
Thêm vào giỏ
Tạo tiện ích Bài viết Hot – Top Comments đã được thêm vào giỏ hàng

Tiện ích này khác với tiện ích Popular Posts hiển thị những bài viết được xem nhiều nhất.Script trong thủ thuật sau đây sẽ lọc những bài viết được bình luận nhiều nhất trong blogspot để tạo ra tiện ích mà tôi đặt tên là Hot Posts. Tiện ích này hiển thị tiêu đề bài viết và số nhận xét cho mỗi bài viết. Thiết nghĩ đây cũng là một tiện ích cần thiết cho blogspot, bên cạnh tiện ích Popalar Posts sẵn có của Blogger.

Bt đu tin ích nào:

Bước 1.

Đăng nhập Blogger, vào Thiết kế (Design) >> Chỉnh sửa HTML (Edit HTML)

Đặt đoạn code bên dưới vào trước thẻ </head>

<script type='text/javascript'>

//<![CDATA[

// Hot Posts Widget styled by Huynh-nhat-ha.blogspot.com

getHP=function(d){document.write(d)};

hotPost = function(u,t,c,b) { this.url = u; this.tit = t; this.comm = c; this.body = b };

var sortAllPosts=[];

sortAllPostsRecopilation = function (json) {

var total,entry,i,x,arr,lnk,com,ttle;

total = json.feed.entry.length;

for(i=0; i < total; i++){

entry=json.feed.entry[i];

for (x=0; x < entry.link.length; x++){

arr = entry.link[x];

lnk = (arr.rel=="alternate" ? arr.href : lnk);

if(arr.rel=="replies"){

com = (arr.type=="text/html" ? parseInt(arr.title,10) : com);

}

}

ttle = entry.title.$t;

txt = ('summary' in entry ? entry.summary.$t : entry.content.$t);

sortAllPosts.push(new hotPost(lnk,ttle,com,txt));

}

sortAllPosts=sortAllPosts.OrderMaxMin();

};

Array.prototype.OrderMaxMin = function(){

var max=0;

var tmp=[];

var x,i,post;

for(i=0; i<this.length; i++){

post=this[i];

max = ( post.comm > max ? post.comm : max);

}

for(x = max; x>=0; x--){

for(i=0; i<this.length; i++){

post=this[i];

if(post.comm == x){

tmp.push(post);

}

}

}

return(tmp);

};

Array.prototype.DisplayHotPosts = function(max,txt) { for(var i=0; i<max;i++){ p=this[i]; getHP(p.tit.link(p.url)+" ("+p.comm+" nhận xét)<br/>"); }};

//]]>

</script>

Lưu Template.

Bước 2.

Vào Page Elements. Trên sidebar thêm một tiện ích HTML/Javascript và đặt đoạn code sau đây vào phần nội dung tiện ích (đặt tên tiện ích là Bài viết Hot hay tên gì đó tùy ý bạn).

<div id='HotPosts'>

<script src='http://chipkool.blogspot.com/feeds/posts/default?alt=json-in-script&callback=sortAllPostsRecopilation&max-results=999' type='text/javascript'></script>

<script type='text/javascript'>sortAllPosts.DisplayHotPosts(7,00);</script>

</div>

Thay Chipkool.blogspot.com bằng tên miền của bạn,số 7 thành số bài viết bạn muốn hiển thị:

Lưu ý nếu bạn rành về CSS thì có thể định dạng CSS cho tiện ích này theo kiểu như sau.

#HotPosts {

….
}
#HotPosts a {

}

Theo Bloggerism.tk