If you’re using Blogger (blogspot), you can see that there is no random posts widget for Blogger blogs. So I make this widget for this purpose. The widget will show a number of posts (which can be modified) in a random order. This is a good way for Blogger users to suggest more content to visitors.
To add random posts widget to Blogger, go to “Dashboard” → “Layout”, click on “Add a gatget” and select type HTML/Javascript. Then paste the following code into the widget content:
To add random posts widget to Blogger, go to “Dashboard” → “Layout”, click on “Add a gatget” and select type HTML/Javascript. Then paste the following code into the widget content:
- <div id="random-posts"></div>
- <script type='text/javascript'>
- function getRandomPosts(json) {
- var maxEntries = 10;
- var numPosts = json.feed.openSearch$totalResults.$t;
- var indexPosts = new Array();
- for (var i = 0; i < numPosts; ++i) {
- indexPosts[i] = i;
- }
- indexPosts.sort(function() {return 0.5 - Math.random()});
- if (maxEntries > numPosts) {
- maxEntries = numPosts;
- }
- var container = document.getElementById('random-posts');
- var ul = document.createElement('ul');
- for (i = 0; i < maxEntries; ++i) {
- var entry = json.feed.entry[indexPosts[i]];
- var li = document.createElement('li');
- var a = document.createElement('a');
- a.title = entry.title.$t;
- for (var j = 0; j < entry.link.length; ++j) {
- if (entry.link[j].rel == 'alternate') {
- a.href = entry.link[j].href;
- break;
- }
- }
- a.appendChild(document.createTextNode(entry.title.$t));
- li.appendChild(a);
- ul.appendChild(li);
- }
- container.appendChild(ul);
- }
- </script>
- <script src='/feeds/posts/summary?alt=json-in-script&callback=getRandomPosts&max-results=999999' type='text/javascript'></script>
To change the number of random posts will be shown, change the value of
maxEntries
in the 4th line (the default value is 10).
- var maxEntries = 10;
After that, save the widget and refresh your blog, you’ll see the random posts right in your blog.
We have great collection of Best tricks and tutorials, Bloggingtrainings.blogpsot.com is a Blog Providing with Blogger widgets, help, blogger tips, blogger tricks, hacks, Blogger Gadgets,Plugins and Blogger resources with great skills and templates.practical SEO Tips and all things Blogging,is about Blog tricks & tips, Traffic generation, Backlinks, Search engine optimization, Web designing, E money, Social media, Facebook tricks,Blogging Discussion, Tips & Tricks,logging tips, tricks, how-tos, news, tools and resources, bloggingtrainings.blogspot presented in easy to understand tutorials.Keep visiting us if any links is not working or you want sme more help, then keep looging at bloggingtrainings.blogspot.com.or contact us 0323-7591466.
0 Komentar untuk "Random Posts Widget For Blogger free"