On my previous post, we talk about how to display blogger random post with thumbnail, whether it is in sidebar widget or after your footer, the goal is to show the readers what is others post that we have, so they can easily picked what article they liked, today I show you another method to do that, and its about how to display random post blogger without thumbnail, see image below:
For display it on your sidebar widget, you must go to Dashboard, click Layout and click add Gadget, scroll down to find HTML/Javascript gadget, click it and copy below code inside it, then save:
<!-- Random Post Start --> <style> #ramdomcat{float:left; margin-top:0px; margin-bottom:10px} #ramdomcat ul{float:left; margin:0px; margin-left:20px; padding:0px; font-size:14px} #ramdomcat li{list-style:disc outside url("http://2.bp.blogspot.com/-NcWoSJbuheg/Utjpc3PoLSI/AAAAAAAAAlA/Bp1xTt7G0UM/s1600/kotak2.png"); width:auto; margin-bottom:0;margin-top:0;padding:0;vertical-align:middle;} #ramdomcat a{font-family: 'open sans',arial,sans-serif;text-decoration:none; color:#0F0F0F; font-size:14px} #ramdomcat a:visited {color:blue; text-decoration: none} #ramdomcat a:hover{color:red} </style> <script type='text/javascript'> var relatedpoststitle=""; </script> <script type='text/javascript'> var relatedTitles = new Array(); var relatedTitlesNum = 0; var relatedUrls = new Array(); function random_results_label(json) { for (var i = 0; i < json.feed.entry.length; i++) { var entry = json.feed.entry[i]; relatedTitles[relatedTitlesNum] = entry.title.$t; for (var k = 0; k < entry.link.length; k++) { if (entry.link[k].rel == 'alternate') { relatedUrls[relatedTitlesNum] = entry.link[k].href; relatedTitlesNum++; break; } } } } function removeRandomDuplicate() { var tmp = new Array(0); var tmp2 = new Array(0); for(var i = 0; i < relatedUrls.length; i++) { if(!contains(tmp, relatedUrls[i])) { tmp.length += 1; tmp[tmp.length - 1] = relatedUrls[i]; tmp2.length += 1; tmp2[tmp2.length - 1] = relatedTitles[i]; } } relatedTitles = tmp2; relatedUrls = tmp; } function contains(a, e) { for(var j = 0; j < a.length; j++) if (a[j]==e) return true; return false; } function showRandomLabels() { for(var i = 0; i < relatedUrls.length; i++) { if(relatedUrls[i]==currentposturl) { relatedUrls.splice(i,1) relatedTitles.splice(i,1) } } var r = Math.floor((relatedTitles.length - 1) * Math.random()); var i = 0; if(relatedTitles.length>1) document.write('<ul>'); while (i < relatedTitles.length && i < 20 && i<maxresults) { document.write('<li><a href="' + relatedUrls[r] + '">' + relatedTitles[r] + '</a></li>'); if (r < relatedTitles.length - 1) { r++; } else { r = 0; } i++; } document.write('</ul>'); } </script> <div id="ramdomcat"> <script type="text/javascript" src="/feeds/posts/default?alt=json-in-script&callback=random_results_label&max-results=10"></script> <script type="text/javascript"> var currentposturl=""; var maxresults=10; removeRandomDuplicate(); showRandomLabels(); </script> </div> <!-- Random Post End -->
To display random posts related for your label (categories) , find and edit this code below:
src="/feeds/posts/default?alt=json-in-script change to src="/feeds/posts/default/-/yourLabel?alt=json-in-script example: src="/feeds/posts/default/-/Blogger%20Guides?alt=json-in-script
And how many post will display, find this code below (you will find two code and change both):
var maxresults=10; change to var maxresults=5; //type your value here
Now you can show you post accordance your label, display it as you wish.
That's it and thank you.
Problem in this widget: Definetely it show random post but only two types of random post shows. When go to home page there is random post, visit next page post will change, but again when we go to next page then post of 1st page will show again.
ReplyDeleteplease try this amazing Randon popst widget with thumnaol for blogger. visit and get random post widget code . http://www.twotricks.com/2015/09/add-random-post-widget-with-thumbnail.html
ReplyDeleteThanks you for this. www.techknowcab.com
ReplyDeleteThanks for sharing for me this is very useful
ReplyDeleteCyfrus Support