Post Summary and Thumbnail with Javascript

I've known for a long time that my next blog design would have truncated posts. Post truncation was not well welcomed when it started being a bit more common on popular blogs, but I always thought that the reasons for truncated posts was absolutely valid and beneficial, and I still do! When I started looking into this and I realized that the real way to truncate posts was to go back to every single post and insert the jump break. 1) That did not seem like a fun time to me, 2) it did not look the way I wanted it to look. I imagined there would be an other way to do this, to automate it, and make it look like I wanted.

I started looking for how to do it with blogger, but the only thing I found was the jump break method. So I started to look for blogs that had what I wanted. I found the blog Megan Brooke Handmade Blog that had a post on truncated posts and that's when I saw what I wanted:



The hiccup? These post thumbanils and summaries, as they are called, were generated from a wordpress template/ theme/ childtheme: Genesis. So I couldn't exactly see how they were generated. But that gave me a new search term: post summary with thumbnail. At the same time as I figured this out, I was also browsing through XO Misse's blog and found the exact post that was useful for this! But the original Javascript is from here.

I also found this tutorial for an updated and more customizable script version, but I could not make it work properly, and in the end was not more customizable for me so I stuck to the original script. The problem I had with the custom version was that the read more link would not lead to the full post, even if it was the permalink (ie item page) and I had put the script between conditionnal if tags for index type pages only.

I did change a few things from the original script, even if I am very unfamiliar with Javascript, since I recognized some patterns with CSS.
- Changed the float of the image to right
- Adjusted the size of the image
- Adjusted the length of the summary
- Changed the text link to Continue Reading... and removed the title of the posst from this line/link
- Changed the float of the Continue Reading link to left, and adjusted the padding; I also moved the style line in the body section to the CSS section for easier stylability



One thing that I cannot figure out how to do or even if I CAN do it is to have the images generated by the script to be responsive, as in have the width of the image be a percentage of the width of the container. I can only put a fixed width, which will also stretch smaller images to be that size, which is annoying. I don't think that will be an issue with the real blog as I think my images will all be bigger than that anyway.



I did try putting a % in the place of the px value. If I put 100%, then the image would not be resized and appear it's true size. Good for small images as they were now actually small and not stretched(above), but the other images were displaying too big. If I put say 50%, the images were 50% of their original size, but the remainder 50% was just white space, as in the text would not be able to fill up the space not taken up by the image, so this tactic was useless. And I'm back to square one. If anyone know how to go around that I would love to know!!


With image width set to 100%


With image width set to 50%

So for now I'm leaving it like this: fixed image width of 300, height of 250. At least it keeps things proportionnal, I think it uses the width if a landscape image, and the height if a portrait image, but I have yet to test that theory.


I'll probably have to adjust these values once on my the real blog, so that it looks good.

No comments:

Post a Comment