Cutiseo xin tổng hợp tiện ích bài viết liên quan cho blogger của các trang cho các bạn tham khảo và lựa chọn mẫu riêng cho mình.
Cách làm:
Đăng nhập Blogger => Mẫu => Chỉnh sửa HTML => thêm đoạn code sau vào trước </herad>
Và chèn đoạn code sau vào sau nó:
Chúc bạn thành công
<!-- Start Related posts by Cuti -->
<b:if cond='data:blog.pageType == "item"'>
<script type='text/javascript'>
//<![CDATA[
var relatedTitles=[],relatedTitlesNum=0,relatedUrls=[],thumburl=[];
function related_results_labels_thumbs(f){for(var e=0;e<f.feed.entry.length;e++){var g=f.feed.entry[e];relatedTitles[relatedTitlesNum]=g.title.$t;try{thumburl[relatedTitlesNum]=g.media$thumbnail.url}catch(h){s=g.content.$t,a=s.indexOf("<img"),b=s.indexOf('src="',a),c=s.indexOf('"',b+5),d=s.substr(b+5,c-b-5),thumburl[relatedTitlesNum]=-1!=a&&-1!=b&&-1!=c&&""!=d?d:"undefined"!==typeof defaultnoimage?defaultnoimage:"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxyFbi72f33b4Gkvvjk_dwzjRBn54Y0Iid6f2tPO3G2gCcmIobaIbKkDj32OWanT8qlhz2Se0eWnp_UMjU31V86D_pHxD6vf-QYqza3YP_LlDuqFKP-NBVPUi40NUrh33lGFXQjcJNESA/s1600/noimage-namkna-blogspot-com-ngoctra.png"}60<relatedTitles[relatedTitlesNum].length&&
(relatedTitles[relatedTitlesNum]=relatedTitles[relatedTitlesNum].substring(0,60)+"...");for(var i=0;i<g.link.length;i++)if("alternate"==g.link[i].rel)relatedUrls[relatedTitlesNum]=g.link[i].href,relatedTitlesNum++}}
function removeRelatedDuplicates_thumbs(){for(var f=[],e=[],g=[],h=0;h<relatedUrls.length;h++)contains_thumbs(f,relatedUrls[h])||(f.length+=1,f[f.length-1]=relatedUrls[h],e.length+=1,g.length+=1,e[e.length-1]=relatedTitles[h],g[g.length-1]=thumburl[h]);relatedTitles=e;relatedUrls=f;thumburl=g}function contains_thumbs(f,e){for(var g=0;g<f.length;g++)if(f[g]==e)return!0;return!1}
function printRelatedLabels_thumbs(f){for(var e=0;e<relatedUrls.length;e++)if(relatedUrls[e]==f||!relatedTitles[e])relatedUrls.splice(e,1),relatedTitles.splice(e,1),thumburl.splice(e,1),e--;f=Math.floor((relatedTitles.length-1)*Math.random());e=0;0<relatedTitles.length&&document.write("<h2>"+relatedpoststitle+"</h2>");for(document.write('<div style="clear: both;"/>');e<relatedTitles.length&&20>e&&e<maxresults;)document.write('<div class="lienquan"><a style="text-decoration:none;padding:3px;float:left;"'),
document.write(' href="'+relatedUrls[f]+'"><img style="width:185px;height:145px;border:1px solid #A8A8A8;padding:4px;background:#fff;margin-right:4px; float: left;" src="'+thumburl[f]+'" /><span style="color: #006633;font-family: Arial;font-size: 12px;font-weight: normal;text-align: justify">'+relatedTitles[f]+"</span></a></div>"),e++,f<relatedTitles.length-1?f++:f=0;document.write("</div>");relatedUrls.splice(0,relatedUrls.length);thumburl.splice(0,thumburl.length);relatedTitles.splice(0,relatedTitles.length)}
;
//]]>
</script>
<style type='text/css'>
#related-posts {float:center;text-transform:none;height:100%;min-height:100%;padding:0;margin:auto;box-shadow: 0px 0px 8px #616D7E;
-webkit-box-shadow: 0px 0px 8px #616D7E;
-moz-box-shadow: 0px 0px 8px #616D7E;}
#related-posts a:hover {background-color:#d4eaf2}
.lienquan {background: #f5f5f5;height:200px;float: left;padding-left: 1px;width: 205px;margin:1px;overflow:hidden;line-height:1.4em}
.related-posts {margin: 0;padding: 0;font-size:14px;font-weight:bold}
.related-posts ul {margin: 0;padding-top: 5px}
.related-posts ul li {background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMeiORTkjVYHbmASRaBAYcv-HDqkZEAgpvl9Q6u0Kr9RQgCR0ZpRRtwAZdGKX8zXIc8UesM7KWGgJc_Xr7kIVqgkyOKjB8Jat-S7fWrZwHX8nfWy32SEYgcfn1o41L-yGXGmCFj7ggttOi/s1600/icon.jpg) no-repeat top left;list-style-type: none;margin: 0 0 2px 5px;;padding: 2px 0 0 18px;word-wrap: break-word}
</style>
<script type='text/javascript'>
//<![CDATA[
var titles=new Array();var titlesNum=0;var urls=new Array();var time=new Array();function related_results_labels(c){for(var b=0;b<c.feed.entry.length;b++){var d=c.feed.entry[b];titles[titlesNum]=d.title.$t;for(var a=0;a<d.link.length;a++){if(d.link[a].rel=="alternate"){urls[titlesNum]=d.link[a].href;time[titlesNum]=d.published.$t;titlesNum++;break}}}}function removeRelatedDuplicates(){var b=new Array(0);var c=new Array(0);e=new Array(0);for(var a=0;a<urls.length;a++){if(!contains(b,urls[a])){b.length+=1;b[b.length-1]=urls[a];c.length+=1;c[c.length-1]=titles[a];e.length+=1;e[e.length-1]=time[a]}}titles=c;urls=b;time=e}function contains(b,d){for(var c=0;c<b.length;c++){if(b[c]==d){return true}}return false}function printRelatedLabels(a){for(var b=0;b<urls.length;b++){if(urls[b]==a){urls.splice(b,1);titles.splice(b,1);time.splice(b,1)}}var c=Math.floor((titles.length-1)*Math.random());var b=0;document.write("<ul>");if(titles.length==0){document.write("<li>Không có bài vi?t liên quan</li>")}else{while(b<titles.length&&b<20&&b<maxresults){document.write('<li><a href="'+urls[c]+'" title="'+time[c].substring(8,10)+"/"+time[c].substring(5,7)+"/"+time[c].substring(0,4)+'">'+titles[c]+"</a></li>");if(c<titles.length-1){c++}else{c=0}b++}}document.write("</ul>");urls.splice(0,urls.length);titles.splice(0,titles.length)};
//]]>
</script>
</b:if>
<!-- End Related posts by Cuti -->
Tiếp theo bạn tìm đến<b:include data='post' name='related-posts'/>
Và chèn đoạn code sau vào sau nó:
<!-- Related posts by Cuti -->
<b:if cond='data:blog.pageType == "item"'>
<div style='margin-bottom:5px;clear:both'/>
<span style='background-color: white; color: #004175; font-family: Arial; font-size: 15px; font-weight: bold; line-height: 20px; text-indent: 10px;'>Các tin khác</span>
<div class='related-posts'>
<b:loop values='data:post.labels' var='label'>
<script expr:src='"/feeds/posts/default/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels"' type='text/javascript'/>
</b:loop>
<script type='text/javascript'>var maxresults=12;removeRelatedDuplicates();printRelatedLabels('<data:post.url/>');</script>
</div>
<div class='clear'/>
<div id='related-posts'>
<b:loop values='data:post.labels' var='label'>
<script expr:src='"/feeds/posts/default/-/" + data:label.name + "?alt=json-in-script&callback=related_results_labels_thumbs&max-results=6"' type='text/javascript'/>
</b:loop>
<script type='text/javascript'>
var currentposturl="<data:post.url/>";
var maxresults=6;
var relatedpoststitle="";
removeRelatedDuplicates_thumbs();
printRelatedLabels_thumbs();
</script>
</div>
<div class='clear'/>
</b:if>
<!-- Related posts by Cuti -->
Chúc bạn thành công
0 nhận xét:
Đăng nhận xét