How to make an automatic Carousel slider based on labels?

In this tutorial I will discuss how to create automatic Carousel slider based on your labels in blogger. All you have to do only replace with your own label and the slider will work based on the label that you add in Edit HTML template. I made this carousel slider was very simple and only used jCarousellite script without adding easing effects or mousewheel.

carousel slider johny

  1. You must login to blogger with your account
  2. After that select the blog that you want to add slider.
  3. Go to the template >> Edit HTML and check the expand widget templates, don't forget to backup your template first.
  4. And then place this following codes above ]]></b:skin>:
    #carousel{width:950px;height:185px;margin-bottom:0px;position:relative;display:block}
    #carousel .container{position:absolute;left:49px;width:895px;height:185px;overflow:hidden;background:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjSU2grsPWrqGqIaRue2JxnQSwNjtqWrsH3oPeHwe1XJGwBHERtxtGwjW08OrAfHznjhfWRFk8kHWGhLVkgYsNcrW8GBmWlrDTy3uXS97HvWRk7owIB5pIv8QR_Kgk8Edp4rXx1FuZHE4/s1600/scroller-bg.png) repeat center}
    #carousel #previous_button{position:absolute;width:49px;height:185px;background:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJit41fskKhMw2GVMIDAh9SezgXZdHi1LS_-irCUBi0Q8VN94CLm8c0NkYjDbTZpuaU2GslfaNQUZIrYCyJMPmHpFDVvD6CWvQB9QwWomnUsl788BWzeIrpgpNxfsTAMXht5kQMJbD4jo/s1600/prev.png) center;z-index:100;cursor:pointer;border-right:1px solid #ccc}
    #carousel #previous_button:hover{background:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrpVuh4DpYg9lABCds2_sdKVPDphCAFNudXiPJTVSBhVF174RzWc4jfxg60f4vONZtZ7uHpL2Nn5IqFIFMCG0ydD3UsyqHxIFARYAUi48X34u94LhUxODCEcZC_x3jYF0ZqbR1t6gld10/s1600/prev.png) center}
    #carousel #next_button{position:absolute;right:0;width:49px;height:185px;background:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1dTtEPJzcsgZTWXz8dONsOX2IR_zPFA38SLPJUKhlaEj3VimuqAJ1W679E-XM9Lb9ary4sH0LDvnvrHq-eoZ_IuVoN0aVvkC6HIMpP16mPxu9ehXLWG7Vvg11VoNU9CtJu8-Hc72RK1c/s1600/next.png) center;z-index:100;cursor:pointer;border-left:1px solid #ccc}
    #carousel #next_button:hover{background:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqR8RYxVbau5_5muI6ZHPL863dm6aTbtPGeTUL1a1isFBZDoZ6Duu2AbXjPThqn7EraMNxXeEFeSRnMNVigHEgoT03S_tSx2zyQh1f1GPRFtQ_-ifhI0sV08W0lVb9wh0qDsUeELjZBBA/s1600/next.png) center}
    #carousel ul{width:100000px;position:relative;margin-top:10px}
    #carousel ul li{background:#fff url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgy9i8lJEqTr69YO8UZCTTuQO-sQG_KY6ZaSF8xfWxDpevsS1QNaUGU9wy_WGZx_aJ5QtfZL1UI38GVZh_QB9PsqSKgnZ7tZwvH6w4jnmY8QRX-Zw4b5qo7HQqw7RkWv-HtMCV5esHVxJ0/s1600/main.png) repeat-x top;display:inline;float:left;text-align:center;font-weight:700;font-size:.9em;line-height:1.2em;border:1px solid #ccc;width:145px;height:150px;margin:0 4px 20px 7px;padding:6px;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;}
    #carousel ul li:hover{filter:alpha(opacity=75);opacity:.75;}
    #carousel ul li a.slider_title{color:#222;display:block;margin-top:5px}
    #carousel ul li a.slider_title:hover{color:#cd1713}
    #carousel a img{display:block;background:#fff;margin-top:0}
    Look at some codes with the blue color above, that's the width and height of the slider in the demo that I made, change with your own size depend on your template width.
  5. Still in Edit HTML, add this following code above </head> :
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' type='text/javascript'/>
    <script src='https://masolis-javascript.googlecode.com/svn/trunk/carousellite.js' type='text/javascript'/>

    <script type='text/javascript'>
    //<![CDATA[
    imgr = new Array();
    imgr[0] = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKosRQUwBifxxt25-RmvnHpE_QoWCujqaf_bvf3LisiTlrkAwG6YHcWcH1WZB60oMgFx_oPrweDBtP0VOJ-hspp6_nn4PgBIMmMTxh9uDi6O6gopvwp-GivCbPLh0hI0PZV1YH89o6PBo/s1600/no+image.jpg";
    showRandomImg = true;

    aBold = true;

    summaryPost = 140;
    summaryTitle = 25;

    numposts1 = 15;
    label1 = "news";

    function removeHtmlTag(strx,chop){
    var s = strx.split("<");
    for(var i=0;i<s.length;i++){
    if(s[i].indexOf(">")!=-1){
    s[i] = s[i].substring(s[i].indexOf(">")+1,s[i].length);
    }
    }

    s = s.join("");
    s = s.substring(0,chop-1);
    return s;
    }
    function showrecentposts(json) {
    j = (showRandomImg) ? Math.floor((imgr.length+1)*Math.random()) : 0;
    img = new Array();
    document.write('<ul>');
    for (var i = 0; i < numposts1; i++) {
    var entry = json.feed.entry[i];
    var posttitle = entry.title.$t;
    var pcm;
    var posturl;
    if (i == json.feed.entry.length) break;
    for (var k = 0; k < entry.link.length; k++) {
    if (entry.link[k].rel == 'alternate') {
    posturl = entry.link[k].href;
    break;
    }
    }

    for (var k = 0; k < entry.link.length; k++) {
    if (entry.link[k].rel == 'replies' && entry.link[k].type == 'text/html') {
    pcm = entry.link[k].title.split(" ")[0];
    break;
    }
    }

    if ("content" in entry) {
    var postcontent = entry.content.$t;}
    else
    if ("summary" in entry) {
    var postcontent = entry.summary.$t;}
    else var postcontent = "";
    postdate = entry.published.$t;
    if(j>imgr.length-1) j=0;
    img[i] = imgr[j];
    s = postcontent ; 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!="")) img[i] = d;
    //cmtext = (text != 'no') ? '<i><font color="'+acolor+'">('+pcm+' '+text+')</font></i>' : '';
    var month = [1,2,3,4,5,6,7,8,9,10,11,12];
    var month2 = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
    var day = postdate.split("-")[2].substring(0,2);
    var m = postdate.split("-")[1];
    var y = postdate.split("-")[0];
    for(var u2=0;u2<month.length;u2++){
    if(parseInt(m)==month[u2]) {
    m = month2[u2] ; break;
    }
    }

    var daystr = day+ ' ' + m + ' ' + y ;
    var trtd = '<li class="car"><div class="thumb"><a href="'+posturl+'"><img width="145" height="100" class="alignnone" src="'+img[i]+'"/></a></div><p><a class="slider_title" href="'+posturl+'">'+posttitle+'</a></p></li>';

    document.write(trtd);
    j++;
    }
    document.write('</ul>');
    }
    //]]>
    </script>
    Notes:
    See the red URL script above, that's the latest series jQuery.min.js script code that I use to made this slider. And if you've found jQuery.min.js although with the different series in your template, the red codes no longer need to insert. There must be only one jQuery.min.js in your template, it is up to the serial number, if possible the latest version.
    Blue code (15) : amount of your post that display in the slider. news was a label that I choose to show up in slider.
  6. Next step you must call the slider to appear in your blog. Place this following code above <div id='main-wrapper'>:
    <b:if cond='data:blog.pageType != &quot;item&quot;'>
    <div id='carousel'>
    <div id='previous_button'/>
    <div class='container'>
    <script>
    document.write(&quot;&lt;script src=&quot;/feeds/posts/default/-/&quot;+label1+&quot;?max-results=&quot;+numposts1+&quot;&amp;orderby=published&amp;alt=json-in-script&amp;callback=showrecentposts&quot;&gt;&lt;/script&gt;&quot;);
    </script>   
    <div class='clear'/>
    </div>
    <div id='next_button'/>
    </div>
    <script type='text/javascript'>
    (function($) {     $(document).ready(function(){
    $(&quot;#carousel .container&quot;).jCarouselLite({
        auto:4000,
        scroll: 1,
        speed: 800,   
        visible: 5,
        start: 0,
        circular: true,
        btnPrev: &quot;#previous_button&quot;,
        btnNext: &quot;#next_button&quot;
        });
        })})(jQuery)   
    </script>
    </b:if>
    You can also put the following codes in the bottom of your navigation menu or you can also placed in your footer side, that's depend on your needs.
  7. The final step, save templates and see the results.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.