Monday, February 20, 2012
Well, now i'd like to disscuss about "How To Create A Random Widget On Blogger Blog?". Similar to Recent Post widget, this random post widget has the ability to list posts on your blog with as many posts as you set. The only difference betwen random and recent post is that this random post will list posts randomly and that which posts that are generated will be always different just on every load, while recent post is based on date release which means that it will be updated only in a condition where a new post is published. It could be good to add this widget into your blog as it will load/display even your old or buried posts that poeple might won't find them accidentally.

Some what it's not that complicated to add this widget into your blog, not at all. What you have to do to add it is just to copypass some lines of code into your blog, you don't even need to edit your template code. Pay attention on the below.

1. Go to your blogger dashboard.
2. Go to design.
3. Click on add gadget where you suppose the widget to show up.
4. After, you'll be taken to the gadget page, just click on/add the Html/Javascript widget and then simply copypass the code below into the text box.

To be the lesser arrangement code in the text box above looks like the below:

< script type="text/javascript">
var randarray = new Array();
var l=0;
var flag;
var numofpost= 20;
function randomposts(json) {
var total = parseInt(json.feed.openSearch$totalResults.$t,10);
for(i=0; i < numofpost;)
{ flag=0; randarray.length=numofpost; l=Math.floor(Math.random()*total);
for(j in randarray) {
if(l==randarray[j]) { flag=1; }}
if(flag==0&&l!=0) { randarray[i++]=l; }}
document.write('< ul>');
for(n in randarray) { var p=randarray[n];
var entry=json.feed.entry[p-1];
for(k=0; k <; k++) {
if([k].rel=='alternate') {
var item = "< li>" + "< a href=" +[k].href + ">" + entry.title.$t + "< / a> < / li>";
document.write(item); }}
document.write('< / ul>'); }
< / script>
< script src="/feeds/posts/default?alt=json-in-script&start-index=1&max-results=10000&callback=randomposts" type="text/javascript">< / script>

5. Save your widget and check if your random post is running properly, and don't forget to say thank you to me. And by the way, saying "Thank You", poeple could be charged with "$" in my country. -


Post a Comment