• MONETIZE YOUR BLOG WITH INFOLINKS

    Infolinks is the perfect resource to monetize your website or blog using contextual ads.

  • SEO GUIDE FOR BEGINNERS.

    Search engines help users find pages on a particular topic. That's exactly why they become great allies in your battle to attract good visitors. So here you got a SEO Guide for Beginners.

  • 33 TIPS TO GET MORE TRAFFIC

    No matter if your blog is new or you has been writing during a year on it, all bloggers should look for ways to generate more traffic. Remember, Traffic = Money. I will give you 33 tips to make your blog a successful blog

  • MAKING MONEY WITH ADSENSE

    If you want to make money with advertising, I show you how to improve your earnings from ADSENSE.

  • 25% DISCOUNT. BEST HOSTING FOR BLOGS

    Now you can get a 25% Discount Coupon for Host Gator. The best hosting company. Read the review.

  • HOW TO BE ON THE FIRST PAGE OF GOOGLE

    Being on the first page of Google is like having 15 minutes of fame. The vast majority of visits would come from Google. These are the 5 most important aspects we have to take in mind.

  • SECRETS OF BLOGGING INCOME

    A book written by two of the best professional bloggers that will give you everything you need to know how to start a blog, improve it and make money with it.

  • EARN MONEY UPLOADING FILES

    Internet it's a great source of income and exist the posibility of making money just by uploading files to websites.

  • EARN MONEY ONLINE WITH EASY JOBS

    With Minute Workers you can expect to earn $10 per day easily doing simple jobs that anyone can do.

Monday, June 27, 2011

Put Random Posts in the Sidebar of your Blog




Let's learn how to put a Gadget in the sidebar that contains Random Posts of your Blog.

This will help to your readers to navigate easily in your blog and see interesting posts that aren't in the front page of your blog.

The point it's keep your visitors more time reading your blog.

In Blogger go to Layout>Page Elements and click on "Ad a Gadget" in the sidebar.
Now choose the HTML/JavaScript Gadget and paste the following code:


<div id="random-posts">
<script type="text/javascript">
function getRandomPosts(json) {
var maxEntries = 5;
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="http://URL OF YOUR BLOG/feeds/posts/summary?alt=json-in-script&callback=getRandomPosts&max-results=999" type="text/javascript"></script>
</div>

Add



Replace the number "5" in red by the numbers of posts that you want to appears and the text "URL OF YOUR BLOG" in red by the actual url of your blog.

We have done, now you have Random Posts in your Blog.
Enjoy!

Share It!

2 Comments:

Rajesh said...

this is for blogger right..??

Tonythanh said...

It is not work in my site www.lemenbros.com, I dont know what is ther reason for this widget, please show me, is it widget for blogspot??

Post a Comment