Skip to main content

How to add Random post widget with Image Thumbnails

How to add Random post widget with Image Thumbnails

Random post widget helps a lot to increase your page impression. If you have larger posts, it is not easy task visitors to find all posts, so this widget is very helpful and also reduce your bounce rate. In this article, I am introducing you how to add a random post widget with image thumbnails on your blog.

Also Read:
How To Create Dropdown Menus With Social Icons In Your Blog
How to Add all in one subscription box to blog

 Adding Random Post Widget

  1. Login to your blogger account and go to the layout of the blog
  2. Click on new gadget and select HTML/JavaScript.
  3. After adding gadget paste the following code 
  <style>
#random-posts img {
    border-radius: 10px;
    float: left;
    margin-right: 5px;
    width: 75px;
    height: 75px;
    background-color: #F5F5F5;
    padding: 3px;
    transition: all 0.2s linear 0s;
}
#random-posts img:hover {
    opacity: 0.6;
}
ul#random-posts {
    list-style-type: none;
    padding: 0px;
}
#random-posts a {
    font-size: 12px;
    text-transform: uppercase;
    padding: 0px auto 5px;
}
#random-posts a:hover {
    text-decoration: none;
}
.random-summary {
    font-size: 11px;
    background: none;
    padding: 5px;
    margin-right: 8px;
}
#random-posts li {
    margin-bottom: 10px;
    border-bottom: 1px solid #EEEEEE;
    padding: 4px;
}
</style>
<ul id='random-posts'>
<script type='text/javaScript'>
var randomposts_number = 5;
var randomposts_chars = 110;
var randomposts_details = 'yes';
var randomposts_comments = 'Comments';
var randomposts_commentsd = 'Comments Disabled';
var randomposts_current = [];
var total_randomposts = 0;
var randomposts_current = new Array(randomposts_number);
function randomposts(json) {
    total_randomposts = json.feed.openSearch$totalResults.$t
}
document.write('<script type=\"text/javascript\" src=\"/feeds/posts/default?alt=json-in-script&max-results=0&callback=randomposts\"><\/script>');
function getvalue() {
    for (var i = 0; i < randomposts_number; i++) {
        var found = false;
        var rndValue = get_random();
        for (var j = 0; j < randomposts_current.length; j++) {
            if (randomposts_current[j] == rndValue) {
                found = true;
                break
            }
        };
        if (found) {
            i--
        } else {
            randomposts_current[i] = rndValue
        }
    }
};
function get_random() {
    var ranNum = 1 + Math.round(Math.random() * (total_randomposts - 1));
    return ranNum
};
</script>
<script type='text/javaScript'>
function random_posts(json) {
    for (var i = 0; i < randomposts_number; i++) {
        var entry = json.feed.entry[i];
        var randompoststitle = entry.title.$t;
        if ('content' in entry) {
            var randompostsnippet = entry.content.$t
        } else {
            if ('summary' in entry) {
                var randompostsnippet = entry.summary.$t
            } else {
                var randompostsnippet = "";
            }
        };
        randompostsnippet = randompostsnippet.replace(/<[^>]*>/g, "");
        if (randompostsnippet.length < randomposts_chars) {
            var randomposts_snippet = randompostsnippet
        } else {
            randompostsnippet = randompostsnippet.substring(0, randomposts_chars);
            var whitespace = randompostsnippet.lastIndexOf(" ");
            randomposts_snippet = randompostsnippet.substring(0, whitespace) + "&#133;";
        };
        for (var j = 0; j < entry.link.length; j++) {
            if ('thr$total' in entry) {
                var randomposts_commentsnum = entry.thr$total.$t + ' ' + randomposts_comments
            } else {
                randomposts_commentsnum = randomposts_commentsd
            }; if (entry.link[j].rel == 'alternate') {
                var randompostsurl = entry.link[j].href;
                var randomposts_date = entry.published.$t;
                if ('media$thumbnail' in entry) {
                    var randompoststhumb = entry.media$thumbnail.url
                } else {
                    randompoststhumb = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbA2uS-UhzAN9PR7zHLI62hXXRwJf1uvdFVPymtLxdPxix04198gs_6XzxTJhl78w8TZWhtiumCSfNTGclzUrO_udKOZYpL9FOVhjIg64V7aNW6mGCT6d5kntEuLGbjve8hJ1tH5-7ncM/s1600/no_thumb.png"
                }
            }
        };
        document.write('<li>');
        document.write('<a href="' + randompostsurl + '" rel="nofollow"><img alt="' + randompoststitle + '" src="' + randompoststhumb + '"/></a>');
        document.write('<div><a href="' + randompostsurl + '" rel="nofollow">' + randompoststitle + '</a></div>');
        if (randomposts_details == 'yes') {
            document.write('<span><div  class="random-info">' + randomposts_date.substring(8, 10) + '.' + randomposts_date.substring(5, 7) + '.' + randomposts_date.substring(0, 4) + ' - ' + randomposts_commentsnum) + '</div></span>'
        };
        document.write('<br/><div class="random-summary">' + randomposts_snippet + '</div><div style="clear:both"></div></li>')
    }
};
getvalue();
for (var i = 0; i < randomposts_number; i++) {
    document.write('<script type=\"text/javascript\" src=\"/feeds/posts/default?alt=json-in-script&start-index=' + randomposts_current[i] + '&max-results=1&callback=random_posts\"><\/script>')
};
</script>
</ul>

Random Post option 

Change the Red Values if you want to modify

  1. Thumbnail dimension; Change the thumbnails of Pixels in post replace the 75x value.
  2. Summery length, Modify the summery length to change this 110 value.
  3. Font Size for posts and summary, Yu can modify the 11px value and the title 12px value. 
Now save the widget and view your blog, it randomly change your blog posts. 

Comments

Popular posts from this blog

How to increase backlinks in 2015? Free backlink builder

A backlink is one type of algorithm that refers to incoming links to your site or pages. Backlinks play significant role to improve your search engine ranking and get more audience. They help to earn good money from the internet. Today’s post I am introducing top 10 backlinks building sites in 2015. Many online websites allow you to build some backlinks for your site. Let us view the sites to create free backlinks Imtalk . Org Imtalk basically a forum and offers many tools. It submits your sites more than 2500 pages. It offers many worthy tools like site directory submitter, bookmarks page etc. Imtalk create pages on different sites with a backlink to your site. Freebacklinkcreator . Com It submits your site thousands of do follow backlink websites. It offers speedy backlinks to your blog or website. A2z-Seo-Backlinks.Com It is a powerful tool to submit your link on different sites. The great feature of this backlink generator is that it also ping your link to search eng

Best web hosting sites for WordPress in 2015

It is important for us to have the best website or blog for the business promotion. A good blog or website depends upon the good hosting company. Only a right web hosting company fulfills our dreams. Thousands of web hosting companies are available in their global market and their number raising day by day. Among those who many companies available in the market, in this article I introduce you top 10 hosting companies. 1. BlueHost It is always recognized as the leader in the industry. Its rates very cheap and low-cost. It is approximately 20,000 website or blog hosts every month in the market. They are in business since 1996 and become the one of the best hosting company. It has excellent servers, customer support center and good hosting packages. It offers unlimited disk space, unlimited domain hosting, unlimited email accounts and many more. Another beneficial feature is that it offers a good referral program for earning money. 2. Hostgator It is one of the greatest webs

10 Best Creative Domain Name Generator Tools

Domains are very significant part of a commercial enterprise and its branding. Attractive and easy domain name also helps to get huge traffic. If you want to create a new website or blog and do not have an idea about selecting a good domain name, then there is an easy solution to your problem. In this post, I describe 10 Best Creative Domain Generator Tools that help you to get ideas for your new domain. 1. NameBoy This is a worthy and reliable creative domain name generator tool. Thousands of people all over the world use NameBoy. Boy recommends you numerous domain name when you entered primary and secondary word of your domain. You can also find sold domain names by this generator. 2. DomainsBot DomainsBot an immediate and trusted domain name generator tools. It helps you to find the domains based on extensions. The main advantage is that you can check premium domains and free domain lookup to get owner’s information. 3. Dot-o-mator Dot-o-motor is much relating to NameBo