Pages

A Great Auto Readmore with cropped thumbnail for blogger blogspot

In this tutorial, I will show you how to make a great Auto Readmore with cropped thumbnail for blogger blogspot. This tutorial also fix the problem for Static Page when applying this auto readmore script.


Just follow the steps below.

First, Login to your blogger account, click Design, click Edit HTML, then click Expand Widget Templates.

Find code below (hit Ctrl+F on your keyboard).
]]></b:skin>
and replace with this code:
.crop-containr{float:left;width:160px;height:120px;border:1px solid #ddd; background:#f3f3f3; margin:0px 10px 1px 0; padding:3px;}
.crop{overflow:hidden;width:160px;height:120px;border:0px solid #eaeaea;}
.crop img{margin-top:-6px;margin-left:-6px;opacity:1;}
.crop img:hover{opacity:.7;}

]]></b:skin>

    <script type='text/javascript'>
    var thumbnail_mode = &quot;float&quot; ;
    summary_noimg = 400;
    summary_img = 300;
    img_thumb_height = &quot;&quot;;
    img_thumb_width = 190;
    </script>

    <script type='text/javascript'>
    //<![CDATA[
    /******************************************
    Auto-readmore by Kentshin - http://blogthemeplates.blogspot.com
    ********************************************/
    function removeHtmlTag(strx,chop){
    if(strx.indexOf("<")!=-1)
    {
    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);
    }
    }
    strx = s.join("");
    }
    chop = (chop < strx.length-1) ? chop : strx.length-2;
    while(strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1) chop++;
    strx = strx.substring(0,chop-1);
    return strx+'';
    }

    function createSummaryAndThumb(pID){
    var div = document.getElementById(pID);
    var imgtag = "";
    var img = div.getElementsByTagName("img");
    var summ = summary_noimg;
    if(img.length>=1) {
    imgtag = '<span style="float:left; padding:0px 0px 0px 0px;"><div class="crop-containr"><div class="crop"><img src="'+img[0].src+'" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></div></div></span>';
    summ = summary_img;
    }

    var summary = imgtag + '<div>' + removeHtmlTag(div.innerHTML,summ)+ '...' + '</div>';
    div.innerHTML = summary;
    }
    //]]>
    </script>

You can set the size or the appearance by customize the set of the red colored text shown above.

After all, find this code:
<data:post.body/>
and replace with this code:
<!-- START Auto READMORE -->
<b:if cond='data:blog.pageType != "item"'>
<b:if cond='data:blog.pageType != "static_page"'>
<div expr:id='"summary" + data:post.id'><data:post.body/></div>
<script type='text/javascript'>createSummaryAndThumb("summary<data:post.id/>");</script>
<span class='rmlink' style='float:right; margin-top:20px; display:inline'>
<a expr:href='data:post.url' style='padding:5px; background-color:#eee;-webkit-border-top-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-bottomright: 5px; border-top-left-radius: 5px; border-bottom-right-radius: 5px;'>Read More</a>
</span>
</b:if>
</b:if>

<b:if cond='data:blog.pageType == "item"'> 
<data:post.body/>
</b:if>
<b:if cond='data:blog.pageType == "static_page"'>
<data:post.body/>
</b:if>
<!-- END Auto READMORE -->

Now, your blog already looks nice and neat. Good Luck.

18 comments:

  1. Thank you very much for this useful information. :)

    ReplyDelete
  2. this is an excellent tutorial. One thing though, I've noticed it doesn't work so well on IE 8 and 9. This appears to be due to the "height" tag not having a value, which results in an image with no height. Works fine in Firefox and Chrome.

    The solution is to change the code to remove the following line:

    height="'+img_thumb_height+'px"

    This seems to solve the problem on all major browsers :)

    ReplyDelete
    Replies
    1. thank you thank you! I ve been trying to fix it for a whole week!

      Delete
  3. How can I use it to just crop images in thumbnails? I dont' wanna read more code. I just wanna that the images that I upload in blogger be cropped when I use thumbs option in editor.
    thanks

    ReplyDelete
  4. This is a great resource! I was just wondering if there's anyway to get this code to display a thumbnails of a youtube video in each post, if that post isn't using a static jpeg?

    My guess is it's not supported, but if there's a way to alter the code to allow for this, that would be great.

    ReplyDelete
    Replies
    1. Did you ever get answer for this? I've been searching for the same thing

      Delete
  5. Thank you very much, I have been looking for this for a long time. I don't like how the post thumbnail cropped the images because it destroys the image dimension - not all images posted are square and thumbnail make it square.

    ReplyDelete
  6. I hate thumbnails with distorted proportion and this works fine for me. Thank you so much!
    Another thanks goes to Laurence Norah for making this code working in internet explorer.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. I find code data:post.body/ multiple times... Which one should I replace?

    ReplyDelete
  9. Very nice, thanks (y)!

    ReplyDelete
  10. This Script make me simple, I was search for this kind of Codes longback and everywhere get the ans "there is no such". but you proven some thing new and awesome

    Hats UP!!!

    ReplyDelete
  11. I cant get it to work! Im basically just trying to resize the main blog pictures that appear in the main page without making them look compressed but no luck :/

    ReplyDelete
  12. i cant find the expand widget button .i am using blog spot too .help me

    ReplyDelete
  13. Thank you for this code, it works, but its font size is higher than my whole blog font size. How can I change its font size?

    ReplyDelete