Adding beautiful related post widget with thumbnail for blogger
(Adding beatiful related post widget with thumbnail and title for blogspot)
Demo:
Step 1: Go to => edit HTML and then paste the below code before </head> tag
<!-- Start Related posts by namkna.blogspot.com --> <b:if cond='data:blog.pageType == "item"'> <script src='http://dl.dropbox.com/u/- Custom height and width to fit your blog template66256041/lien-quan/namkna- blogspot/related-img-by- namkna-nt.js' type='text/javascript'/> <style type='text/css'> #related-posts {float:center;text-transform: none;height:100%;min-height: 100%;padding:0;margin:10px 0 5px 0;} #related-posts h2{margin:0;background: url(http://2.bp.blogspot.com/- G9sN-9S0pFQ/TvB1Mde4NGI/ AAAAAAAAAWo/WEMaH2u0JME/s1600/ newslienquan.jpg) no-repeat scroll left 0 transparent;height: 16px;} #related-posts a:hover {background-color:#d4eaf2} .lienquan {background: #ddd;height:57px;float: left;padding-left: 1px;width: 173px;margin:1px;overflow: hidden;line-height:1.4em} .related-posts {margin: 0;padding: 0} .related-posts ul {margin: 0;padding-top: 5px} .related-posts ul li {background: url(http://2.bp.blogspot.com/- xqifPunAyFI/TaJlWbZEcGI/ AAAAAAAABZ0/AWsX5sEj8Co/s1600/ list.png) 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 namkna.blogspot.com -->
Save Template.
Bước 2: Search this line:
<div class='post-footer-line post-footer-line-2'/>or
<div class='post-footer-line post-footer-line-1'/>and paste the below code affter one of the above lines.
<!-- Related posts by namkna.blogspot.com --> <b:if cond='data:blog.pageType == "item"'> <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= 9"' type='text/javascript'/> </b:loop> <script type='text/javascript'> var currentposturl="<data: post.url/>"; var maxresults=9; var relatedpoststitle="" ; removeRelatedDuplicates_ thumbs(); printRelatedLabels_thumbs(); </script> </div> <div style='margin-bottom:5px; clear:both'/> <img border='0' src='http://3.bp.blogspot.com/ -yiVfzquaerE/TvRKvbCfxaI/ AAAAAAAAANc/0sfbyPSDBy4/s1600/ cac-tin-khac-namkna-blogspot- com-ngoctra.jpg'/> <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'/> </b:if> <!-- Related posts by namkna.blogspot.com -->
Customizing:
- max-results=9" number of posts with thumbnail.
- var maxresults=12 number of posts in list.
Have a look at the below photo to understand more.
Đăng nhận xét