February 28, 2008

How to Create Post Summaries in Blogger Layouts Blogs

One of the questions I am asked most about my blog is how I create post summaries on my main and archive pages.

The hack I use for this is Ramani's "selective expandable posts". This hack enables me to choose whether my posts are summarized or not, and provides a "Read full post" link only for those which I have chosen to summarize.

Whereas I would normally refer readers to Ramani's original post to learn how to implement this technique, many readers have expressed their difficulties in using this, and Ramani seems unavailable for support. So I have decided to write a full explanation of how to use this hack in the hope that this will answer many of your questions, and enable you to use this hack in your own Blogger layouts blogs.

Please note: This "selective expandable posts" hack was written for Blogger layouts blogs (those which use widgets). If you need to learn how to use such a technique for Classic Blogger templates, please refer to this post instead.

How the selective expandable posts hack works

This technique uses a combination of JavaScript and Blogger code to display your selected portion of a blog post on your main, archive and search pages. On item (post) pages, the full content of your post will be displayed.

This technique is very useful for bloggers who write long posts, or who prefer to provide a "teaser" of their full post on the main page, which would encourage readers to read the whole article on item pages instead.

Before installing the selective expandable posts hack to your blog, you should be aware of two things:

  • Only your future posts (and any previous posts you choose to edit) will feature a summarized version on the main pages of your blog. This is because you must use a post template to make the summaries appear. Those posts which do not include this template will not be summarized.
  • To ensure the summary hack works, you will find it necessary to edit your posts in HTML mode, rather than using the rich text editor. Again, this is due to the necessity of the post template; if you edit in compose mode, you will run the risk of accidentally deleting some code which is not visible in the rich text editor.

If these considerations are something you can live with, you're ready to install the "selective post summary" hack.

How to Install the Selective Post Summaries Hack

This isn't the easiest hack to install in a Blogger template. In fact, it took me a few attempts to get this right the first time I installed it! So I would advise you to remember two important things:

Back up your existing template before making any changes whatsoever!

You should always back up your blog template before making any changes to the template code. It is even more important to back-up before installing this hack, as we are dealing with the display of your blog posts, rather than a simple edit to your styling code!

Read each step fully, familiarize yourself with the code, and then read it again!

It is important to pay attention to detail when installing this, otherwise you may place code in the wrong place and get that dreaded "Your template could not be parsed" message.

Also, there may be slight differences to the code which you will be looking for in your template. I will point this out where appropriate, along with the alternatives which may be present in your template.

Here is my step by step guide to installing the selective post summary hack in your blog template:

  1. Back up your existing template code!

    To do this, go to Layout>Edit HTML in your Blogger dashboard, and click on the link which says "Download full template". This will allow you to save a copy of your existing template in XML format which you can use to restore your blog if ever your template edits go awry.
  2. Choose to create a new post. On this page, click on the "Edit HTML" tab so this becomes highlighted. Then in the content box below, paste this entire section of code, exactly how this is written here:
    This is the summary
    <span id="fullpost">
    This is the rest of the post
    </span>
    Then save this post.

    This will only be a temporary post, to help you understand if the following edits you make are working. Once you have installed this hack into your template, you can delete this post.
  3. Next go to Layout>Edit HTML in your Blogger dashboard, and check the "Expand widget templates" box.
  4. We now need to add the required JavaScript code to the head section of your blog template.

    This is the easy part of the installation! Simply copy all of the code on this page to your clipboard (you can do this easily using the keyboard shortcuts CTRL+A followed by CTRL+C).

    Next, locate this line in your blog template:
    </head>
    Paste the code from your clipboard directly before this line.
  5. Here comes the tricky part...

    In your blog template, you will need to locate the DIV section which contains this line:
    <p><data:post.body/></p>
    In many templates, this section will look something like this:
    <div class='post-body>
    <p><data:post.body/></p>
    <div style='clear: both;'/> <!-- clear for photos floats -->
    </div>
    However, the class of the containing DIV section may be called something different, such as:
    div class='post'
    div class='entry'
    div class='post-body entry-content
    In the case of third party templates, this could well be something else entirely!

    The best way to locate this is to search for <data:post.body/> using the CTRL+F function in your browser, then take a look at the surrounding code to work out where you need to edit.
  6. Once you have found this section of code, take a look at the code below. I've added some code in red, which is what you will need to add in your own template. As I have explained, the <div class='post-body'> section may be named differently in your own blog template, so do bear this in mind!
    <div class='post-body'  expr:id='"post-" + data:post.id' >

    <b:if cond='data:blog.pageType == "item"'>
    <style>#fullpost{display:inline;}</style>
    <p><data:post.body/></p>
    <b:else/>
    <style>#fullpost{display:none;}</style>

    <p><data:post.body/></p>

    <span id='showlink'>
    <a expr:href='data:post.url'>Read More......</a>
    </span>
    <script type='text/javascript'>
    checkFull("post-" + "<data:post.id/>");
    </script>
    </b:if>

    <div style='clear: both;'/> <!-- clear for photos floats -->
    </div>
    Before you attempt to save your template, I would advise you to preview your blog.

    If you have pasted the code correctly, you will see the test post you created earlier will now feature only the summary, followed by the "Read more..." link, like this:



    If you have pasted the code incorrectly, one of two things will happen: you will either be unable to preview, or your test post will appear in full, rather than as a summary.

    In either case, you should clear all edits you have made, and start again from the top: it's a far better idea to begin the process again, paying attention to every detail, than to try and edit the code!
  7. After you have successfully made the changes outlined above, you can proceed to save your template.
  8. The final step is to add a post template in your blog settings.

    This is the same code we used to add the content to our test post, though this time we will add this as a permanent template which will appear in your post editor each time you write a post.

    Go to Settings>Formatting in your Blogger dashboard, and scroll right down near the bottom of this page where you will see a text box for your post template.

    Inside this box, you must paste the following section of code:
    This is the summary
    <span id="fullpost">
    This is the rest of the post
    </span>
    Be sure to copy and paste this code exactly as you see it here. If you accidentally insert any extra spaces, extra characters or line breaks by typing this manually, you run the risk of breaking the operation of the script.

    Finally, save these settings, and enjoy the convenience of selectively summarizing your blog posts!

Using the Selective Expandable Posts Hack

For me, Ramani's selective post summaries hack has been the most effective method of summarizing my posts. However, when using this hack you may need to change the manner of your blogging habits slightly, and learn how best this can be used.

Here are some tips which I have learned through using this hack on a regular basis, which will probably be useful for you too:

  • You must create and edit your posts in Edit HTML mode. The <span> tags which are included in your new post template will only be visible in Edit HTML mode. If you use the regular "Compose" mode, you may accidentally delete some of the required code, which will cause your posts to be displayed improperly.
  • If you do not want to summarize a post, simply delete all of the post template when creating your post! In this case, there will be no "Read more" link beneath the post, and your complete post will appear on the main pages (ideal for short posts).
  • If you are used to writing your posts in paragraphs using appropriate paragraph code, like this:
    <p>This is a paragraph</p>
    <p>This is another paragraph</p>
    you will need to wrap all of your content in paragraphs, and may need to add the appropriate paragraph tags to the lines in your post template too.
  • When using this hack, you can easily implement Google AdSense code to appear in your post pages only, and can choose to display this within the body of the post itself, as well as above/below your post content.

As I mentioned earlier, this hack will only work for posts which you create after installing the required code and post template. Your existing posts will not be summarized unless you edit them to add the required code inside the post.

If you have a great many posts, I would advise you only to edit the posts which appear on your front page. So if you display seven posts on your home page, you would only need to edit the previous seven posts, if you would like these to be summarized. The reason I advise this is because in my experience, fewer people browse through your archives using the "newer/older posts" links than would search through using the blog search function. This means that your readers' experience would suffer little disruption from seeing older posts in their full form.

Troubleshooting

If ever you notice a "summarized" posts appears strangely, or other posts seem to disappear from beneath this on your main pages, the problem is most likely that you have accidentally deleted the closing </span> tag from the very bottom of your post. Don't worry if this happens, it is easily solved by adding that line right at the very end of your post!

Another possible problem Ramani has noted is that sometimes the "read more" link will appear on archive pages, even for those posts which have not been summarized. This issue is not yet resolved, though if I come across a definitive solution I will be sure to update this post

Final thoughts

This is by no means the only method you could use to summarize your posts (Jackbook has discovered seven different methods), though for most bloggers the selective method will be the most effective and easily maintained choice.

I hope that my explanation of Ramani's excellent hack will help you implement this version of post summaries in your Blogger layouts blog.

If you have any more hints or suggestions for using this hack, please feel free to leave your comments below.



View blog reactions


Related Posts by Categories



Post a Comment 38 Comments:

06 March 2008 14:18 Dav7 said...

Nice!!!

work at the first try!


now 1 question, can I change the "read more" text to my language ?

06 March 2008 14:22 Amanda said...

Glad to know this worked for you, Dav7!

Yes, you can change the "Read more..." text to say anything you like and it will still work fine.

It's regular text, so if you search for this term in your template, you should be able to change the text easily.

Best wishes,

Amanda

06 March 2008 14:31 Dav7 said...

l-o-l amanda, sorry

I was soo happy to be able to make this work that I didn't notice the cod

off course I can change and I already know How :)

I´m printing all your tips and making an arquive to use on future blogs!

keep the good work helping us!

08 March 2008 10:21 free for all said...

it doesn't work for oldest posts

08 March 2008 22:25 Swanie said...

Thank you Amanda for the step by step instructions. It worked in my first attempt. I'll use it when I upgrade my blog to beta. Thanks again.

26 March 2008 10:37 C K said...

Thanks for the infomation. Definitely worth a try!

26 March 2008 15:59 mintblogger said...

Hi Amanda,

Everything in working fine, but I want to align the "Read More" link on right side of the post with bold letters and different color.

Can we do it? I think yes, because in your blog it is right aligned with bold , red color.

Please help.

26 March 2008 22:31 C K said...

Have implemented it! Worked great at the first try. Fantastic set of instructions you got there!

30 March 2008 11:12 ametya said...

Hi amenda, I made minima two coulmn template provided by blogger in to 3 column attractive template by seeing and reading you. But i failed in "read more". At every time i follow the steps given by you, it shows that

"Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
XML error message: Element type "div" must be followed by either attribute specifications, ">" or "/>"."

plz help me....

30 March 2008 15:33 Amanda said...

For Ametya: I think the best way to approach this would be if you can send me your template code by email. Then I can take a look at this for you and send you the template back with the summary hack included.

Hope this will help!

31 March 2008 01:58 Michelle said...

Thanks a zillion!!!

31 March 2008 09:13 ametya said...

I got succeedd but only when one of my blog friend helped me through guidelines. Your and his syntaxs are differnt. I don't know why didn't your guidelines didn't work for me while my friend's syntax worked to me in a single step.And thnk u for ur intrest to help me. I wish all new blogger do get you and my friend like friends in their friend list.

But i want to say a big THANK YOU as ur guidelines helped me to make 2 to 3 column template in a quick and single step. SO a big NEPALI NAMASTE to you and a big THANK YOU too.

05 April 2008 01:15 Internet Marketing Strategies said...

Hey I don't know what I'm doing wrong but the hack it's not working on my blog. I think the problem is on the paragraph code, I may be using the wrong HTML code to wrap the paragraph...

Can any one give me some help please.

Thanks,

Luis Galarza.

08 April 2008 08:56 ametya said...

Hi again amanda, i am monetizing my blog seeing and reading your posts. see my blog, if it is nice then say a big congrats to yourself since reading your articles only i came at this stage.

As my blog is dragging other's articles in my blog means copy pasting, so i would like to request isn't there any ease way so that i can do my work in an ease manner ?? I am right now do copy other's text article through ctrl+c and then in new post i do ctrl+v which is ease but still eat my enough time for the appearance and paragraph changing. Also image copy paste also eating my lot of time.

Isn't there any way so that i just put the URL of that article and i don't have to do anything except clicking on publish post so that i could make my blog as a compilation of good articles found in net.

I hope you have the answer..plz amanda..plz help me....

28 April 2008 10:07 twinks said...

Hi Amanda,

Great tutorial! It worked first time I used it. I'm loving my blog more now..thanks to you.. my post body is more organize now.
Thanks a lot.. keep up the good work! :]
cheers!

29 April 2008 04:08 Tasmanian Arc said...

Thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you

Did I mention thank you enough? No?

Well: thank you

I have looked up about 10 other blogger help sites and groups on this topic and you are the only one that's mentioned that:
div class='post-body

may look like something else on different templates such as:

div class='post'

div class='entry'

div class='post-body entry-content

It may seem obvious to techno-eager beavers but to this newbie it meant the hack worked

YOU LEGEND (yes I am a bit overexcited - I know nothing of HTML and now feel at least a bit tech savvy)

02 May 2008 06:57 Lana said...

I've tried this code and it works! It's great. But I'd like those words "Read more..." to be bold and blue. Is it possible to change it somehow?

Lana

02 May 2008 14:25 Amanda said...

For Tasmanian Arc:

Thank you so much for your lovely comments! I'm glad to know this has worked out well for you :)

For Lana:

The quickest and easiest way to do this would be to add the following few lines just before the closing </b:skin> tag in your template:

#showlink {
font-weight: bold;
color: blue;
}

This will ensure all instances of the "read more" link will appear in strong, blue test. You could change "blue" to a hex value of you prefer a different color to the generic blue this produces though.

Hope this helps!

10 May 2008 01:53 BigGirlsDoItBetter said...

Hi- This is not working for me in the terms of adding a summary. I've followed the directions closely and I'm getting syntax errors. Please help. Thank you.

14 May 2008 05:57 Theresa Komor said...

GREAT! Worked on the first try!

Now, if you could tell me how to get rid of that Blogger bar across the top, I'd be set!

Thanks, Amanda!

15 May 2008 03:48 Anonymous said...

The javascript that i should put already exceeded its bandwidth. i cant continue the next step.

19 May 2008 02:25 Dewan Muda said...

thanks.i works well..anyway,i want to change the "read more" to different text in different post.so,how could i do it?example in post1 i want to display "more pictures" and in post 2 i want to display "read more"?

24 May 2008 01:04 DWiner said...

Gr8 1...it worked for me the first time...considering I'm dummy at coding. Thnx a ton!

24 May 2008 14:06 DWiner said...

In Step 2, you could have said 'Then publish this post' instead of SAVE. I only saved it but did not publish only to realize later what you actually meant.

01 June 2008 23:41 The DINKs said...

I'm pretty sure I can handle this, except that the link to the page that has the code I need to copy does not work - apparently a lot of people are taking your good advice, and the site has exceeded its allotted bandwidth. Help please!

03 June 2008 21:31 DWiner said...

I have a problem in creating Post Summaries on my blog. I did as instructed but you can see the effect here. Could you please help me out rectify this? I have emailed you my templates xml.

10 June 2008 17:16 Isabelle said...

thanks so much! clear, easy to follow directions that worked for me on the first try!

11 June 2008 15:20 Bobby said...

Hello Amanda

Thank you so much! it worked like a charm. At first I was very hesitant to try since it looks very complicated. But you explained it so clearly, even to a newbie like me understands it perfectly.

Thank God for people like you :)

Bobby

19 June 2008 12:35 Swanky said...

Hi. This is probably gonna seem rather odd, but I managed to get this to work the first time I tried it, but when I tried to do the same to my second blog it doesn't work. I have tried everything I can think of, gone through the whole process more than seven times now, and even compared the relevant code from my first blog to that of my second and can not figure out what is going wrong.

When I try to check the code in a preview, I get an error on the preview page, but it doesn't say anything is wrong on the edit page, so I can't even tell you where the code might be going wrong. o_0 Can you think of any reason why this code might work on my first layout (a slightly modified minima) and not on my second (a slightly more modified rounders)? Any light you could shed on this problem would be greatly appreciated, cause I'm completely stumped.

Thanks again for all your great codes and layouts and tutorials and everything else! You really are great. ^_^
~Swanky

20 June 2008 03:52 Swanky said...

Ok, well, never mind. It worked now. Still don't know what I was doing wrong before, but it's all better now, so...

Thanks again for all you great codes and such. Your blog is *so* helpful. ^_^
~Swanky

20 June 2008 08:44 ella said...

If you do not want to summarize a post, simply delete all of the post template when creating your post! In this case, there will be no "Read more" link beneath the post, and your complete post will appear on the main pages (ideal for short posts).

Hi Amanda, thanks so much for the great instructions. I am quoting your above advice though because it doesn't seem to work on me. Even if I erase the span codes in the EDIT HTML section of the "Create a Post" page, the "Read more" link still appears. Is there a way to actually erase this in my short posts?
I will be really grateful for your help, more power to you!

Blessings,
Ella

21 June 2008 15:07 Sparhawk said...

This is a great hack. I applied it to this site: http://seeknomore.blogspot.com/

The problem is that, when I used my comp at work it works, but when I used some comp in a public internet shop it doesn't work. I'm not sure if the version of IE has something to do with it.

03 July 2008 10:19 Tran Tinh said...

It works now with my blog but I only works if I make a post in html mode, not work in compose mode, what happens? As if i post in html mode, link will disappear. Tinh

Here is my blog: http://www.blogviet.info

10 July 2008 14:43 Anonymous said...

hi amanda...
firstly thanks for this instruction..
but i am not very clear on step 3..
can i get some help???plz..
thank you...

10 July 2008 17:29 After Fashion said...

Thank God, after about the tenth time I figured that if you have code other than what is displayed such as div class='post-body entry-content it's easier to delete that and paste what is shown. Thanks for your help, my blog is starting to look great.

14 July 2008 17:36 bnycastro said...

Hey Amanda

excellent resources here on your blog. I am having some trouble getting this hack to work on my blog. I am running a custom template which is 3 columns. I think I have followed the instructions correctly but I am getting a
---
bX-2nuf8g error
---
when I am trying to view the preview or save the template :(
--
I know you are busy with the template [I am liking the minor changes so far] change so any help you can spare when you are free would be much appreciated.

16 July 2008 02:10 J M Van Horn said...

Thanks for the helpful instructions. I have tried this several other times from other sites and I was never able to have it work. :)

19 July 2008 23:13 Anonymous said...

Thank you. Very very new to blogging but thanks to your accessible and comprehsnive instructions I succeeded where I had failed on many attempts with other instructions.

Post a Comment