Skip to main content

Expandable Post Summaries on Blogger Using JavaScript

I hope you read the first part of this article, in which the normal way of expanding post summaries was discussed as a result of a reader query. Here we will see a better, more effective way to expand your post summaries—using JavaScript.

Haven’t you seen professional blogs in which the home page has a number of posts with only summaries and a ‘Read More’ or ‘Continue Reading’ link at the bottom? This is one of the signs of a good blog design. Blogger, by default, doesn’t offer this feature. So, we will see how we can make this available with a JavaScript tweak. Blogger help also has provided the same script.

1. Adding The Expansion Style

In the New Blogger template, go to Layout->Edit HTML and find the tag, <b:skin><![CDATA[. After this tag, add the following code:

.fullpost
{
display:inline;
}
.summary
{
display: none;
}
2. The Expansion JavaScript

Now, you have to add the following JavaScript snippet in the <head> tag, right before the <b:skin> tag.

<script type="text/javascript">
//<![CDATA[
function expandPost() {
var currentText = this.innerHTML;
if (this.nextSibling.nodeName == "#text") {
this.parentNode.removeChild(this.nextSibling);
}
if (currentText == "Continue Reading...") {
this.innerHTML = "Summary Only<br />";
this.nextSibling.className = "fullpost";
}
else {this.innerHTML = "Continue Reading...";
this.nextSibling.className = "summary";
}
}
function postExpansion() {
var anchors = document.getElementsByName("ExpandPost");
for (var i = 0; i < anchors.length; i++) {
anchors[i].onclick = expandPost;
anchors[i].href="#" + i;
}
}
//]]>
</script>

Now, you have to replace the <body> tag with
<body onload='postExpansion();'>.

You can change the strings, 'Continue Reading...' and 'Summary Only' with any other string you like.

3. Modify Post Template

Now, you have to modify the default post template, by going to Settings->Formatting. Add the following code to the post template text area:

<a href="#" name="ExpandPost">More...</a><span class="summary">

</span>
Once done, the above code will automatically appear on your post editor.

4. Enabling the Trick on New Posts

Now, whenever you start a new post, add the summary of the post above the code shown above. The rest of the post has to be added in between the two span tags, i.e., right above </span> tag.

Conclusion

I believe it will be helpful to you. I hope I didn’t err anywhere on the code. It worked just fine when I tested it. However, if you find any trouble doing this, please let me know by the contact form. Also, make certain that you backed up the template before you apply the tweak.

Copyright © Lenin Nair 2008

Comments

  1. its a completed trick and tips for blogger that i can find in here.thank you

    ReplyDelete
  2. Thank you so much! It is working!

    The only problem is that when I change the format of the text from "aligned left" to "aligned left and right" the java code does not funtion any more.

    Is there a fix?

    Thank you again very much...

    ReplyDelete
  3. It may well be some issue in the JavaScript you implemented. Otherwise it should not work that way. Text alignment doesn't affect the working of the JavaScript. If you are getting troubles, you may try the other method of expandable post summaries, without JavaScript: http://cutewriting.blogspot.com/2008/09/expandable-post-summaries-on-blogger.html

    ReplyDelete
  4. I could not get it to work in either of my blogs. But both of them had the "head" part AFTER the b skin part...would that make it not work????

    Sorry...newbie here.

    Kathy

    ReplyDelete
  5. Kathy, may be you included a script part right after the <b:skin> part. But it has to be included after the entire b skin tag which will be like: <b:skin><![CDATA[

    ReplyDelete
  6. WHEW!!!! I figured it out and I say THANK YOU !!!!!

    Kathy

    ReplyDelete
  7. Good to know that, Kathy, would like to see the site you implemented it in. Your profile doesnt give access to the site.

    ReplyDelete
  8. Thank you for letting me know my profile was not public, I went straight away and fixed THAT. My blogs are now on there and once again, thank you for all you do for the community!

    ReplyDelete
  9. Yes, I found it. It's a pleasure to help people like you.
    Thanks for the comments.

    ReplyDelete
  10. Hey Lenin, it doesn't really work. When you click on MORE it sometimes goes to CONTINUE READING but most of the time it simply reloads the blog and leaves the post at MORE, without opening the summary.

    What I'd really like is for it to open the post in a new window containing that post only.

    Michael

    ReplyDelete
  11. Michael, I tested in various blogs. In fact, for it to work, the blog should be using the new blogger layouts structure. Make sure yours does. Also, the blog has to load fully before the javascript code to work, otherwise, it will simply reload. If you still get troubles, let me know. We can fix it up. If you send me the code of your blogger or invite me to be the admin, I will see what the problem is.

    Lenin

    ReplyDelete
  12. Excellent post by Lenin, i tried this "expandable post summaries" with 'Blogger.com help', but it didn't worked, shown some error, then i tried this one amazingly, i had succeeded in just 5 minutes with this simple HTMLcode.. Thank you so much Mr.Lenin.
    Regards,

    ReplyDelete
  13. Satheesh, thanks for the comment. It's my pleasure to help you out.

    ReplyDelete
  14. I am very new to this, and for some reason every time I try to implement this is doesn't work. As I am new, could you please suggest what I may be doing wrong is simple instructions. Any help would be very appreciated. I have been on this computer for almost 5 hours trying different hacks suggested by many forums and none of them seem to be working.

    Thanks again

    ReplyDelete
  15. Hi girlon tour, you must be doing something wrong with it. Are you using blogger layouts? If not, then that may be the problem. I tested it several times before posting here. So it should work normally. Let me know your blog details so that I can do a check. Contact me.

    ReplyDelete
  16. Thanks Lenin. I see that the problem was that the blog was so huge it takes time to load up. I have used it successfully! Beautiful work.

    Michael

    ReplyDelete
  17. Good to know that it worked for you at last, Michael. Thanks for your comment.

    ReplyDelete
  18. Thank you so much. I looked through various pages trying to figure this out and yours worked like a charm.

    ReplyDelete

Post a Comment

Comments are moderated very strictly

Popular posts from this blog

What Is DoFollow? Guide: How to Make Blogspot Blogs Dofollow?

Dear friends, this is a blog notification post. I have decided to make my blog, DoFollow. You will find the comment policy updated on the sidebar about this (please look at the left sidebar). [Edit: The blog is no longer DoFollow due to loads of spam comments it attracted ] Backlinks are very important for your websites. They are like votes cast by one respectable website to another, and they will greatly increase the site’s traffic. When one gets many backlinks, one’s site’s ranking in search engine results will skyrocket. Search engines use programs called search bots or web crawlers to access and index web pages. That’s how you see websites in the search results of Google and Yahoo!. If your site ranks high for any search terms related to the products you promote, you can get several potential customers (a very daunting task indeed). Now, in order for you to get business, you must rank high in search engines , and the most important thing that will help you in this is link build...

Unethical Business Practices by Associated Content (AC)

Useful Resources Freelance job at Constant Content Freelance for a 6 figure income Get paid to write on the Internet 25 Ways to write for income on the Internet Work from home as a virtual assistant Freelance for fortune 500 companies Today’s Internet slogan is ‘Content is King’ . If you have well-written, keyword rich content, without grammatical errors, then you can rank very high on search engine results, thus making a lot of money. With this business idea, several companies have sprung up, and Associated Content (who call themselves, People’s Media Company) is one among them. Here, we will try to find answers to these questions: 1. What exactly is Associated Content (if you don’t already know this)? 2. Is it really worthwhile to work with them? 3. Why should you steer right clear of them? What is Associated Content (AC) Associated Content (AC) is a website, in which you can earn money submitting content (text, video, audio, or images) . Anyone from anywhere in the...

Organic SEO: How It Works?

What really is Search Engine Optimization? (Photo credit: Go Local Search ) In order to have your blog posts reach the top of the search results, you really have to do a lot of thinking. One of these ways that you can experiment with is SEO. Search engine optimization is pretty important even if you have a regular personal blog. Who wouldn't like their stuff seen by more than ten or so people daily? However, the posts that get seen by a hundred thousand people daily are really profitable. They are simply at the top of their search terms and are meant to be good for earnings. If you have strong keywords in your article, they are going to rank you the best in search results. Let's look at some of the important SEO decisions you should make as a webpreneur. 1. Building A Lot of Links If you are keen about getting maximum visits to your blog, one thing you can do is gather as many links as possible from as many sources as possible. A few of the best practices in SEO ca...