Display Most Commented Posts in Blogger

Tiện ích này cho phép hiển thị danh sách các bài viết có nhiều người đang thảo luận (comment) nhất trên blog của bạn. Điều này giúp cho khách viếng thăm blog của bạn nhanh chóng truy cập được các chủ đề đang có nhiều người thảo luận giúp tăng lượng visit cho blog


Chú ý: trước khi chỉnh sửa trong phần HTML các bạn cần backup trước Template đang dùng để tránh bị lỗi.


Hướng dẫn:

Bước 1:  Truy cập vào quản lý Blogger, click Mẫu rồi click tiếp Chỉnh sửa HTML


Bước 2:  Click chuột vào khoảng trống bất kỳ trong khung soạn thảo HTML ở phía dưới rồi ấn CTRL+F để hiện ra khung tìm kiếm rồi gõ </Group>

Bước 3: chèn đoạn code sau vào phía dưới đoạn mã vừa tìm được </Group>

<Group description="Most Commented" selector=".most-commented">
<Variable name="most.commented.background1" description="background color1" type="color" default="#fa4242" value="#ee377a"/>
<Variable name="most.commented.background2" description="background color2" type="color" default="#ee6107" value="#fcad37"/>
<Variable name="most.commented.background3" description="background color3" type="color" default="#f0f" value="#f8e000"/>
<Variable name="most.commented.background4" description="background color4" type="color" default="#ff0" value="#c7e93d"/>
<Variable name="most.commented.background5" description="background color5" type="color" default="#0ff" value="#5ebded"/>
</Group>

Chú ý: nhiều mẫu Template bạn sẽ không tìm được mã </Group> thì bạn sẽ thử tìm đoạn mã khác <b:skin><![CDATA[ rồi thêm đoạn code trên vào phía dưới


Bước 4: Tìm tiếp đoạn mã ]]></b:skin>

Thêm vào phía trên nó đoạn mã sau:

.comment-count {
    padding: 3px 10px;
    background: #fff;
    color: #000;
    font-size: 10px;
    float: right;
}
.most-commented ul {
    padding: 0px !important;
    font-family: Century Gothic, sans-serif;
}
.most-commented ul li {
    list-style-type: none;
    padding: 10px;
    color: #555;
    margin-top: -10px;
}
.most-commented ul li a {
    color: #444;
    font-weight: bold;
    text-decoration: none;
    font-size: 11px;
}
.most-commented ul li img {
    float: left;
    margin: 0px 5px 0px 0px;
    width: 60px;
    height: 60px;
}
.most-commented:nth-child(3n+0) {
    background: $(most.commented.background1);
    width: 100%;
}
.most-commented:nth-child(4n+0) {
    background: $(most.commented.background2);
    width: 95%;
}
.most-commented:nth-child(5n+0) {
    background: $(most.commented.background3);
    width: 90%;
}
.most-commented:nth-child(6n+0) {
    background: $(most.commented.background4);
    width: 85%;
}
.most-commented:nth-child(7n+0) {
    background: $(most.commented.background5);
    width: 80%;
}

Xong ấn "Lưu mẫu"

Bước 5: vào menu "Bố cục", ấn vào "Thêm tiện ích"


Bước 6 : Từ cửa sổ Popup hiện ra, bạn click vào "HTML/Javascript"



Dán đoạn mã dưới đây vào hộp HTML/Javascript

<script type="text/javascript">
function stripTags(s,n) {
    return s.replace(/<.*?>/ig,"").split(/\s+/).slice(0,n-1).join(" ")
}
function mostcommented(feed) {
    var i;
    for (i = 0; i < feed.count ; i++) {
var postURL = "'" + feed.value.items[i].link + "'";
var postTitle = feed.value.items[i].title;
var postthumbnail = "<img src="+feed.value.items[i].postthumbnail+" />";
var postDescription = feed.value.items[i].postdescription;
var postComments = feed.value.items[i].commentcount;
var postList = '<div class="most-commented"><ul><li><div class="comment-count">' + postComments + "</div>" + postthumbnail + "<a href="+ postURL + '">' + postTitle + "</a>"  + '<p>' +stripTags(postDescription,10)+'...</p>' + '</li></ul></div>';
 document.write(postList);
     }
 }
 </script>
<script src="http://pipes.yahoo.com/pipes/pipe.run?
AddUrlHere=http://Your-Blog-Address
&NumberofPosts=5
&_id=2cb5eb603ed55a6264ee1484e5fdd45c
&_callback=mostcommented
&_render=json"
type="text/javascript"></script>

Thay địa chỉ BLog của bạn vào dòng code màu đỏ "http://Your-Blog-Address"
Để hiển thị thêm đoạn mô tả, thay đổi giá trị "10" ở dòng postDescription,10

Nếu không muốn hiển thị ảnh thumbnail và đoạn mô tả thì sử dụng đoạn code sau đây:

<script type="text/javascript">
function stripTags(s,n)
    {
    return s.replace(/<.*?>/ig,"").split(/\s+/).slice(0,n-1).join(" ")
}
function mostcommented(feed) {
 var i;
 for (i = 0; i < feed.count ; i++)
 {
var postURL = "'" + feed.value.items[i].link + "'";
var postTitle = feed.value.items[i].title;
var postComments = feed.value.items[i].commentcount;
var postList = '<div class="most-commented"><ul><li style="margin-bottom: 10px"><div class="comment-count">' + postComments + "</div>" + "<a href="+ postURL + '">' + postTitle + "</a>"  + '</li></ul></div>';
 document.write(postList);
 }
 }
 </script>
<script src="http://pipes.yahoo.com/pipes/pipe.run?
 AddUrlHere=http://Your-Blog-Address
&NumberofPosts=5
&_id=2cb5eb603ed55a6264ee1484e5fdd45c
&_callback=mostcommented
&_render=json"
type="text/javascript"></script>

Để thêm chữ "comment" vào đằng sau số comment giống hình như sau


Tìm đoạn code màu tím <div class="comment-count">' + postComments + "</div>" rồi thêm mã "comment" vào như ví dụ sau:

<div class="comment-count">' + postComments + " comments" + "</div>"
Xem DEMO ngay tại trang web này.

Để cấu hình mầu hiển thị cho các tab truy cập Mẫu >>> Tùy chỉnh


Truy cập tiếp Nâng cao >>> Most Commented để tùy chỉnh lại màu sắc cho tiện ích này. Xong click Áp dụng cho Blog



0 nhận xét: