How to add recent posts slider in homepage

Step 1 - Applying Styles

  1. Go to Blogger Dashboard > Design > Edit HTML. (In new User Interface It Is - Dashboard > Template)
  2. As always download a copy of your template first.
  3. Now find for ]]></b:skin>
  4. Add below code just before ]]></b:skin>


/* START EasySlider */

#slide-container {
    height: 360px;
    position: relative;
    width: 480px;
}

#slider {
    height: 360px;
    left: 25px;
    overflow-x: hidden;
    overflow-y: hidden;
    position: relative;
    width: 480px;
    font-family: calibri;
}

.slide-desc {
    background: transparent url(http://i195.photobucket.com/albums/z105/dantearaujo/darkbg.png) repeat scroll 0 0;
    color: #FFFFFF;
    padding: 10px;
    position: absolute;
    right: 0px;
    text-align: left;
    top: 0;
    width: 200px;
    z-index: 99999;
}

.slide-desc h2 {
    display: block;
}

.crosscol .widget-content {
    position: relative;
}

#slider ul, #slider li,

#slider2 ul, #slider2 li {
    margin: 0;
    padding: 0;
    list-style: none;
}

#slider2 {
    margin-top: 1em;
}

#slider li, #slider2 li {
/*

define width and height of list item (slide)

entire slider area will adjust according to the parameters provided here

*/
    width: 480px;
    height: 360px;
    overflow: hidden;
}

#prevBtn, #nextBtn,

#slider1next, #slider1prev {
    display: block;
    width: 30px;
    height: 77px;
    position: absolute;
    left: -30px;
    text-indent: -9999px;
    top: 71px;
    z-index: 1000;
}

#nextBtn, #slider1next {
    left: 520px !important;
}

#prevBtn, #nextBtn, #slider1next, #slider1prev {
    display: block;
    height: 77px;
    left: 0;
    position: absolute;
    top: 132px;
    width: 30px;
    z-index: 1000;
}

#prevBtn a, #nextBtn a,

#slider1next a, #slider1prev a {
    display: block;
    position: relative;
    width: 30px;
    height: 77px;
    background: url(http://i195.photobucket.com/albums/z105/dantearaujo/prev.png) no-repeat 0 0;
}

#nextBtn a, #slider1next a {
    background: url(http://i195.photobucket.com/albums/z105/dantearaujo/next.png) no-repeat 0 0;
}

/* numeric controls */

ol#controls {
    margin: 1em 0;
    padding: 0;
    height: 28px;
}

ol#controls li {
    margin: 0 10px 0 0;
    padding: 0;
    float: left;
    list-style: none;
    height: 28px;
    line-height: 28px;
}

ol#controls li a {
    float: left;
    height: 28px;
    line-height: 28px;
    border: 1px solid #ccc;
    background: #DAF3F8;
    color: #555;
    padding: 0 10px;
    text-decoration: none;
}

ol#controls li.current a {
    background: #5DC9E1;
    color: #fff;
}

ol#controls li a:focus, #prevBtn a:focus, #nextBtn a:focus {
    outline: none;
}

/* END EasySlider */

Step 2 - Adding JavaScript


  • Now find for </body> tag
  • Add below code just after/below </body> tag.

<!-- Start easy content slider -->
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js' type='text/javascript'></script>
<script src='http://accordion-template.googlecode.com/svn/trunk/easySlider1.7.js' type='text/javascript'></script>
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function(){
 $("#slider").easySlider({
 auto: true,
 continuous: true
 });
});
//]]>
</script>
<!-- End easy content slider  -->
Now save your template.

Adding The Gadget

  • Now go to Page Layout
  • Add a Gadget > HTML/JavaScript
  • Paste below piece of code and save it.

    <div id="slider">
<script style="text/javascript" >
var showpostthumbnails_gal  = true;
    var showpostsummary_gal   = true;
 var random_posts         = false;
 var numchars_gal   = 150;
 var numposts_gal   = 10;
function showgalleryposts(json) {
    var numPosts = json.feed.openSearch$totalResults.$t;
    var indexPosts = new Array();
 document.write('<ul>');
    for (var i = 0; i < numPosts; ++i) {
        indexPosts[i] = i;
    }
 if (random_posts == true){
    indexPosts.sort(function() {return 0.5 - Math.random()});
 }
    if (numposts_gal > numPosts) {
        numposts_gal = numPosts;
    }
    for (i = 0; i < numposts_gal; ++i) {
        var entry_gal = json.feed.entry[indexPosts[i]];
  var posttitle_gal =  entry_gal.title.$t;
        for (var k = 0; k <  entry_gal.link.length; k++) {
            if ( entry_gal.link[k].rel == 'alternate') {
                posturl_gal =  entry_gal.link[k].href;
                break;
            }
        }
  if ("content" in entry_gal) {
            var postcontent_gal = entry_gal.content.$t
        }
        s = postcontent_gal;
        a = s.indexOf("<img");
        b = s.indexOf("src=\"", a);
        c = s.indexOf("\"", b + 5);
        d = s.substr(b + 5, c - b - 5);
        if ((a != -1) && (b != -1) && (c != -1) && (d != "")) {
            var thumburl_gal = d
        } else var thumburl_gal = 'http://i1133.photobucket.com/albums/m596/abu-farhan/Images_no_image.gif';
        document.write('<li><div id="slide-container"><span class="slide-desc"><h2 style="margin:10px 0px;">');
        document.write(posttitle_gal + '</h2>');
        var re = /<\S[^>]*>/g;
        postcontent_gal = postcontent_gal.replace(re, "");
        if (showpostsummary_gal == true) {
            if (postcontent_gal.length < numchars_gal) {
                document.write(postcontent_gal);
                document.write('</span>')
            } else {
                postcontent_gal = postcontent_gal.substring(0, numchars_gal);
                var quoteEnd_gal = postcontent_gal.lastIndexOf(" ");
                postcontent_gal = postcontent_gal.substring(0, quoteEnd_gal);
                document.write(postcontent_gal + '...');
                document.write('</span>')
            }
        }
   document.write('<a href="' + posturl_gal + '"><img src="' + thumburl_gal + '" width="480px" height="360"/></a></div>');
        document.write('</li>');
    }
 document.write('</ul>');
 
}
</script>
<script style="text/javascript">
 var numposts_gal = 6;
 var numchars_gal = 150;
 var random_posts = false; // random posts
</script>
<!-- replace with your web address (marked with red color) -->
<script src="http://yourblog.blogspot.com/feeds/posts/default?orderby=published&alt=json-in-script&callback=showgalleryposts&max-results=999999"></script>
</div>
  • Now replace yourblog.blogspot.com with your own blog url.[Code Line - 10] (Only change blog URL don't change any other things.
  • To change number of post find this var numposts_gal = 6; line in above code. (Code Line - 4)
  • If you want to change number of characters to show in description find this piece of code var numchars_gal = 150; (Code Line - 5)
Now save your all the changes and you are done.Visit your blog to see this beautiful slide.

18 comments:

  1. http://www.Saeedbaba.com

    nice post and nice blog

    ReplyDelete
  2. Is there any way to make this responsive?

    ReplyDelete
  3. title and description never change

    ReplyDelete
  4. INSTEAD OF GETTING A LOAN,,  I GOT SOMETHING NEW
    Get $5,500 USD every day, for six months!

    See how it works
    Do you know you can hack into any ATM machine with a hacked ATM card??
    Make up you mind before applying, straight deal...

    Order for a blank ATM card now and get millions within a week!: contact us
    via {automatedcardsonline@gmail.com}

    We have specially programmed ATM cards that  can be use to hack ATM
    machines, the ATM cards can be used to withdraw at the ATM or swipe, at
    stores and POS. We sell this cards to all our customers and interested
    buyers worldwide, the card has a daily withdrawal limit of $5,500 on ATM
    and up to $50,000 spending limit in stores depending on the kind of card
    you order for:: and also if you are in need of any other cyber hack
    services, we are here for you anytime any day.

    Here is our price lists for the ATM CARDS:

    Cards that withdraw $5,500 per day costs $200 USD
    Cards that withdraw $10,000 per day costs $850 USD
    Cards that withdraw $35,000 per day costs $2,200 USD
    Cards that withdraw $50,000 per day costs $5,500 USD
    Cards that withdraw $100,000 per day costs $8,500 USD

    make up your mind before applying, straight deal!!!

    The price include shipping fees and charges, order now: contact us via
    email address:: {automatedcardsonline@gmail.com

    ReplyDelete
  5. I really enjoy reading and also appreciate your work.
    UI designers

    ReplyDelete
  6. Superb article, a debt of gratitude is Best Buy in order for assembling this! This is clearly one awesome post. Much obliged for the profitable data and bits of knowledge you have so given here.

    ReplyDelete
  7. They maintained regular communication, transparency, and exellent project management.
    corporate branding agencies

    ReplyDelete
  8. Your site is truly cool and this is LIBID Xtreme Caps Valor an incredible rousing article. Much thanks to you to such an extent.

    ReplyDelete
  9. The team could benefit from more consistency in account management staffing.
    user experience agency

    ReplyDelete
  10. Get the best Plano Milling, sandblasting, blackening services in Bangalore

    ReplyDelete
  11. The problem is that you provide may be worth our time and also effort.
    UI company

    ReplyDelete
  12. Thank you, your writing is very useful for blogger users.

    ReplyDelete

  13. That’s really great blog thanks for posting :)
    Welcome to Adam Teller. We are a team of enthusiastic developers and entrepreneurs who decided to convert their common experience into this web store. We hope you’ll like it as much as we do and have a great shopping experience here. Our prime goal is to create a shop in which you can easily find whatever product you need.
    Posture corrector USA

    ReplyDelete
  14. Great Blog,
    DEPENDENCIES AND HOW TO REPAIR THEM
    Alcohol, as well as drugs in modern society, are referred to as one of the most dangerous problems that can only exist. However, despite large-scale campaigns to ban them, in fact, there are individuals in society who try such harmful substances, gradually becoming dependent on them. The appearance of dependence is the most terrible consequence of the use of these substances. The brain is destroyed, cells die, health deteriorates, and a person falls down the social ladder lower and lower, however, he cannot do anything about it, because his body at the biological level itself begins to “ask” for as many of these supplements as possible, because already cannot exist without them. For more visit here Consmed

    ReplyDelete
  15. Im no master, however I trust you simply made a fantastic point.fifa scores You unquestionably completely comprehend what youre talking about, and I can really get behind that.

    ReplyDelete
  16. I read that Post and got it fine and enlightening. If you don't mind share more like that... click here digital marketing course

    ReplyDelete
  17. Your site is helpful.I have benefited a lot from this site.Hope for more.Thank you…SEO Agency

    ReplyDelete