1. Vào Thiết kế > Chỉnh sửa HTML > Tick chọn Mở rộng mẫu tiện ích
2. Tìm trong Template đoạn code tương tự như sau :<div class='post-footer-line post-footer-line-3'/>
hoặc
<div class='post-footer-line post-footer-line-2'/>
hoặc
<div class='post-footer-line post-footer-line-1'/>
và chèn bên dưới nó đoạn code này :
<b:if cond='data:blog.pageType == "item"'>
<div id='post-labels-for-related' style='display:none'><b:if cond='data:post.labels'><b:loop values='data:post.labels' var='label'><data:label.name/><b:if cond='data:label.isLast != "true"'>,</b:if></b:loop></b:if></div>
<div id='post-timestamp-for-related' style='display:none'><data:post.timestampISO8601/></div>
<style type='text/css'>
#related-posts-block {
margin:10px 5px 0 -20px;
font-size:12px;
color:#999999;
text-transform:none;
}
#related-posts-block #related-posts-loading-text{
font-size:18px;
color:#FF0033;
text-align:center;
}
#related-posts-block #related-newest-href {
margin:10px 5px;
}
#related-posts-block #related-newest-href ul{
list-style-image:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNXcehUeUb8oYnQK11wXo6goAStTlHaEf8DoGzhHJQqLzt02GxKg2yJv3ctYTkdNazk9QeP8mrmOsjt4hEp435jlQEvdzmtCpJQ8_mham8HgobdShIRZrQUZow6gif0Q6uNAHuXaeqCBs/);
}
#related-posts-block #related-newest-href #related-newest-title {
font-size:16px;
margin:10px 5px
}
#related-posts-block #related-newest-href a{
font-size:12px;
font-family:Arial, Helvetica, sans-serif;
color:#000000;
}
#related-posts-block #related-older-href {
margin:10px 5px;
}
#related-posts-block #related-older-href ul{
list-style-image:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNXcehUeUb8oYnQK11wXo6goAStTlHaEf8DoGzhHJQqLzt02GxKg2yJv3ctYTkdNazk9QeP8mrmOsjt4hEp435jlQEvdzmtCpJQ8_mham8HgobdShIRZrQUZow6gif0Q6uNAHuXaeqCBs/);
}
#related-posts-block #related-older-href #related-older-title {
font-size:16px;
margin:10px 5px
}
#related-posts-block #related-older-href a{
font-size:12px;
font-family:Arial, Helvetica, sans-serif;
color:#000000;
}
</style>
<div id='related-posts-block'>
<div id='related-posts-loading-text'>Loading related posts... <img align='absmiddle' src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6_uUKpXL2_xeuKbMQHHI1NC0A57YRW-3l5di6irgiInOwlGqxo4133pNFYumz1qAXbgGSPLwtYeJXIXtJ8JFzZziscssdRm9UWeoZahnds08eklW-quQowfKbo3Yjm95ZfCiaSkhvuRM/'/></div>
<div id='related-newest-href'><div id='related-newest-title'/></div>
<div id='related-older-href'><div id='related-older-title'/></div>
</div>
</b:if>
3. Chèn đoạn code bên dưới lên trước thẻ đóng </body>
<b:if cond='data:blog.pageType == "item"'>
<script type='text/javascript'>
//<![CDATA[
var showdate = false;
var max_post = 12;
//]]>
</script>
<script type='text/javascript'>
//<![CDATA[
// Related posts script for Blogger
// version 2.0
// (C) Anhvo
// Homepage: vietwebguide.com
// Please dont remove this copyright when using or redistributing this code
function format(ptime){
return ptime.substr(0,19);
}
function formatdate(d){
var month = [1,2,3,4,5,6,7,8,9,10,11,12];
var month2 = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var m = parseInt(d.substring(5,7),10);
for(var j=0; j<month.length;j++){
if(m==month[j]){
m = month2[j]; break;
}
}
return d.substring(8,10) + "-" + m + "-" + d.substring(0,4);
}
function getRelatedNewestLinks(json){
var entry = json.feed.entry;
if(entry){
for(var k=0;k<entry.length;k++){
var li = document.createElement("li");
if(showdate){
li.innerHTML = "<a href='"+entry[k].link[4].href+"'>"+entry[k].title.$t+"</a>" + ' - <i>' + formatdate(entry[k].published.$t) +'</i>';
}
else {
li.innerHTML = "<a href='"+entry[k].link[4].href+"'>"+entry[k].title.$t+"</a>";
}
if(!checkRelaxLinks("related-newest-href",entry[k].link[4].href)){
document.getElementById("related-newest-href-ul1").appendChild(li);
document.getElementById("related-newest-title").innerHTML = "<img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSF6LpbWhtaBcYCUXV9t29U7CCXo6l2xtryCxL3Cn4y3LIH3zC-1MNRNNhHNSUAcjxlu2WcMdSPwPNxPp0K5cIi05BBawjvdmEIGNokrQ6KvHxwcucbrzdbtLValvacRb-sBk-EMbV53w/'width='347' height='21'>"
}
}
} else {
document.getElementById("related-older-title").innerHTML = "Không có bài nào mới hơn cùng chủ đề";
}
}
function getRelatedOlderLinks(json){
var entry = json.feed.entry;
if(entry){
for(var k=0;k<entry.length;k++){
var li = document.createElement("li");
if(showdate){
li.innerHTML = "<a href='"+entry[k].link[4].href+"'>"+entry[k].title.$t+"</a>" + ' - <i>' + formatdate(entry[k].published.$t) + '</i>';
}
else {
li.innerHTML = "<a href='"+entry[k].link[4].href+"'>"+entry[k].title.$t+"</a>";
}
if(!checkRelaxLinks("related-older-href",entry[k].link[4].href)){
document.getElementById("related-older-href-ul2").appendChild(li);
document.getElementById("related-older-title").innerHTML = "<img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnSuEHYb1EYT19gPakQuT6XH9VYPu5vgEpMe9hLvObEj4lsP6KADjLv6Pi27Ikci38goykPwxyLCki_-DFywE4X9lHfGE0PXHrPpipN7juHag5q0O8rO6RMqTp3rpvJ_ntZf5IL6_4jus/'width='347' height='21'>"
}
}
} else {
document.getElementById("related-older-title").innerHTML = "Không có bài nào cũ hơn cùng chủ đề";
}
document.getElementById("related-posts-loading-text").style.display = "none";
}
function createRelatedJson(min_or_max,cRJ_label,fcn_callback,cRJ_max){
var script = document.createElement("script");
script.src = "/feeds/posts/summary/-/"+escape(cRJ_label)+"?orderby=published&max-results="+cRJ_max+"&published-"+min_or_max+"="+escape(format(document.getElementById("post-timestamp-for-related").innerHTML))+"&alt=json-in-script&callback="+fcn_callback;
script.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(script);
}
function checkRelaxLinks(cid,clink){
var check = false;
var u = document.getElementById(cid);
var a = u.getElementsByTagName("a");
for(var i=0;i<a.length;i++){
if(a[i].href==clink){
check = true;
break;
}
}
var url = location.href.split(".html")[0]+".html";
if(clink==url) check = true;
return check;
}
function createRP(){
var postLabel = document.getElementById("post-labels-for-related").innerHTML.split(',');
var max_ = Math.round(max_post/postLabel.length);
var ul1 = document.createElement('ul');
ul1.id = 'related-newest-href-ul1';
document.getElementById('related-newest-href').appendChild(ul1);
for(var i=0; i<postLabel.length;i++){
createRelatedJson("min",postLabel[i],"getRelatedNewestLinks",max_);
}
var ul2 = document.createElement('ul');
ul2.id = 'related-older-href-ul2';
document.getElementById('related-older-href').appendChild(ul2);
for(var j=0; j<postLabel.length;j++){
createRelatedJson("max",postLabel[j],"getRelatedOlderLinks",max_);
}
}
createRP();
//]]>
</script>
</b:if>
Trong đoạn code trên :
o var showdate = false; : nếu muốn hiện thị ngày đăng thì thay false thành true
o var max_post = 12; : số bài viết tối đa hiển thị là 12 bài.
0 nhận xét:
Đăng nhận xét