41 How to Create Post Summaries in Blogger Layouts Blogs
Thursday, February 28, 2008 /

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.

41 comments:

January 31, 2009 at 3:58 PM Albert said...

Works perfect, check it out on my 765 dofollow social networks list. It saved hundreds of scrolling time and made the post more convenient, thank you! Check it out here.
http://marketopinions.blogspot.com/2009/01/765-dofollow-social-bookmarking-sites.html

February 3, 2009 at 8:10 AM Calculus Entropy said...

Everything works, except each of my postings say:

expr:id='"post-" + data:post.id' >

I'm using the Minima format.

Thanks,
Calculus

PS--Whenever I look for hacks, I always seem to end up coming back to your page in the end. Good work!

February 7, 2009 at 12:04 AM tiquee said...

i m seeing read more at the end of my post what should i do

February 12, 2009 at 6:45 AM smellyKen.com said...

Thanks for this useful code.

It saves alot of space on my blog and i learnt a new code ^^. Thank you.

February 18, 2009 at 8:37 AM CroppyCat said...

I get this error as well I think it is this line not written properly. I had


div class='post-body entry-content'
and i changed it to this

div class='post-body' expr:id='"post-" + data:post.id'

Can u please advise? thanks!


"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 "/>"."

February 25, 2009 at 12:18 AM Cindy said...

Amanda,

Thank you so much! Your post is so clear! I got it right on my first try hehe~ Thank you thank you!!

by the way, (i know you're getting so many questions already, sorry) how do you change "read more" to a different font, or a different font size?? I'd just like it to be a bit bigger..

Thanks!!!

February 25, 2009 at 1:36 AM
cabalen said...

Hi,

It worked perfectly to my site right the first time I tried :-). Excellent work. Hopw more tips to come...

March 5, 2009 at 7:58 PM Mr Simons said...

Hi,

its a great solution, it inspired me to make a quicker solution that can be found here:
http://flashismo.blogspot.com/2009/03/easy-way-to-make-post-summarries-in.html

in this solution you dont have to add the div tags to each post, but instead it fixes the posts height in the front page.
i hope this helps others..

Gideon

March 9, 2009 at 8:41 AM lily ng said...

hi

it worked ok in my blog but when my friends log in to my blog using other search engine besides explorer, they have all the html codes all on top and the sidebars are all over.

help!!

thanks

March 12, 2009 at 8:36 PM LASIK Guider said...

Hi Amanda,

Your tips are great...
The hack works fine ..but i want to know how to make the post footer elements(labels, timapstams,...etc) show up only in the full post page and not in the main page after summaries.

Thanks!

March 18, 2009 at 10:30 PM
Anonymous said...

Thanks a lot for the trick.
Your tips and tricks are great...
The hack works fine..........

***** * * * * * * * ***
* **** *** * * * ** *
* * * * * * * * * ***
*
***

March 21, 2009 at 6:18 AM
Radith Prawira said...

@LASIK Guider

I got the same req like you, but somehow i figured it out by reading http://catalog-tutorial.blogspot.com/2007/12/bikin-blog-lebih-dinamis.html , the post's written in Indonesian.

Quite simple actually, it is by hiding the element you wish to. By adding <b:if cond='data:blog.pageType == "item"'> before the element and closed the code using </b:if>

ex : in my blog,

<div class='post-footer-line post-footer-line-1'>
<b:if cond='data:blog.pageType == "item"'> <span class='post-author vcard'>
<b:if cond='data:top.showAuthor'>
<data:top.authorLabel/>
<span class='fn'><data:post.author/></span>
</b:if>
</span>

look at the code's structure

for live demo here's my blog : Thumbshit

--

and i did that per each element i wish to hide.

hope it help,

Radith ^_^

March 21, 2009 at 9:03 AM bossgu said...

very nice,thanks Amanda,and how to set"Related Posts by Categories",

March 26, 2009 at 9:55 AM
Radith Prawira said...

my comment somehow got filtered out T_T even i didn't do any spam, ( or it is thought as spam, coz i made a live link there?) i'm truly deeply ask for your apology then, i didn't mean that. i just wanna give the live example of what i'd wrote before ( regarding to LASIK Guider's comment

@LASIK Guider

use this code on post footer element you'd like to hide :

<b:if cond='data:blog.pageType == "item"'>

and closed by :

</b:if>

--

p.s : i hope you don't get offended Amanda, just wanna share what i know ,maybe it'll help others like you have help me and millions like me :)

and maybe you'd like to consider using a more reliable comment system as i see several 'anonymous' people spamming your comment section.

best regard, Radith

March 27, 2009 at 12:11 PM
Arun said...

Hey
I can't see the page with jscript header code. It says the permitted bandwidth has been exceeded. Can you please provide an alternative?

April 2, 2009 at 10:45 AM sauravjit said...

hey there
i need your help and its urgent
check my website http://www.musicnlifestyle.com

there are lots of images on my site in different posts and the blog starts transferring data from photobucket or imageshack(where i used to store my images) even if the post is not open(by using expandable post trick) at my homepage.

how can i sort it out?

April 6, 2009 at 5:50 PM Cian Prendiville said...

Thank you so much. I have always read posts of people thanking others for there tips, but never understood why people were so thankful. Now i know. I've just spend hours on end trying out different suggestions from accross the internet, none of which worked. Maybe it was that the template i have is weird, or to do with beta or something. But yours worked. I think it is just so thorough, in a sense 'chunky' that it just works no matter what it's used with, where as the others have all been cut down, to make them sleeker but as a result it assume that your posts are called posts, not "post-body entry-content" which I had.

Anyway. Why don't google just add a bloody button in the editing box that does all this at one click!

April 8, 2009 at 11:08 PM Offrd2001 said...

Amanda,

Your site is the third I have tried for getting the proper code for displaying expandable posts. Ive had nothing but luck wit all your previous hacks. Now this one......its not working. With the other sites codes I was at least getting read more... at the bottom of the full post but with yours Im getting absolutely nothing :( A little help please.

Dave

April 27, 2009 at 5:07 PM
Anonymous said...

I found a simpler solution to adding post summaries that uses PURE CSS (no javascript). It seems to fix a lot of the problems that i was getting with the other solutions. Might be worth taking a look at this solution as well.
http://simplerthanyouthink.blogspot.com/2009/04/blogger-expandable-post-summary.html

May 1, 2009 at 6:01 AM Who's B? said...

I have been looking everywhere for this information. This was very clearly described and it was accomplished with a breeze. Thank you.

May 6, 2009 at 10:57 AM Mivta said...

How to make automatic post summary??
see my blog with automatic post summary.
.
.
http://tag02.blogspot.com

May 9, 2009 at 2:05 PM
Anonymous said...

I have used such approach and it worked out till some days ago. Now, nothing happens when you clik on the read more link.

Could be some new java filter or something related to the blogger system?

Thx...

May 10, 2009 at 12:44 PM
Anonymous said...

It worked till for ca. a week the unfold function does not work anymore. Has blogger changed something in hes codes?

May 11, 2009 at 6:09 AM ARTISHOK said...

Hello,
I had the code working on my blog but a week ago it suddely stopped working. It shows the summaries, but the readmore button does not work. By investigating the problem I can not find the body part of the code, its like it's not there anymore... Any idea how this could happened? Has blogger scanged something?
I can not make it a new, since I cant find where to but the code...

The part of the code before the head is in place, but the rest I cant find.

May 15, 2009 at 9:53 AM Ali Qayyum said...

i have problem actually,
i already posted 300 posts in my blog
but when i done this code on templetes, this disappeared my posts
what should i do
http://alisoft7.blogspot.com

June 19, 2009 at 11:39 PM Andreea-Roxana Comanescu said...

Hello, I'm Andreea and I have a problem with the layout. When I try one on the internet, and I copy the html code, I get this error:
"Error mesage XML: The markup in the document following the root element must be well-formed."

I've seen you've helped someone with an similar problem. Pleeeese help me too!

June 21, 2009 at 1:38 AM Harwinder a.k.a. Brain Washer said...

Thanks for the detailed explanation, Amanda.

I have noticed one issue with this approach. If my posts contain list elements like "ul" or "ol", the entire post shows up on the main page followed by the "Read more ..". Basically if the text contains lists, everything shows up.

For posts that don't contain lists, it works fine.

Is there any way to fix this?

Thanks

June 27, 2009 at 6:50 AM cmongood said...

U ARE TRULY THE F-IN BEST!!!! I'VE BEEN TRYNA DO THIS ON OTHER SITES ALLLLLLLLLLL MORNING!!!! I LOVE YOU, YOU ROCK!!!

July 2, 2009 at 5:04 AM Harwinder a.k.a. Brain Washer said...

Hello Amanda,

I've posted these comments earlier also but they were not published. Sending them again:

I have tried a few different versions of this 'post summary' approach, but all seem to have one problem. They don't work if the contents within the 'span' elements have list elements like (ul or ol). It works for posts that don't have lists.

Have you seen this problem? Is there any way to fix it?

Thanks.

July 8, 2009 at 4:56 AM Shivani said...

Hi Amanda,
Great tutorial!!
It worked first time I used it...thanx alot ;)

http://xperiencemedia.blogspot.com

July 20, 2009 at 1:42 PM paul said...

wow you are amazing. I read 10 different tutorials on how to do this before I found yours....and yours was the only one that did what I wanted! thanks so much!

Now if I could only figure out how to get my header to not appear on my posts...

let me know if I can do anything for you! (seriously)

http://makesomethingcooleveryday.blogspot.com

July 22, 2009 at 10:08 PM Lahjaetsivä said...

Hi Amanda,
I used this "Ramani's summary" in my blog, worked well (expect one post).

How does summarizing affect on SEO?

Thank you for great tutorials!

July 25, 2009 at 7:34 AM Mélanie said...

Thank you very much!!

July 27, 2009 at 11:43 AM
Anonymous said...

Brilliant! The most straightforward and helpful directions I've found

August 10, 2009 at 4:50 AM Administrator said...

Is great..but I have a question..I can do this trick into a gadget? Because if I can , I want to modify my template into a magazine template..and this trick will be great!!

August 12, 2009 at 8:47 PM
football said...

Thanks for this.I saw someone had same problem like me..when all this you wrote i paste to my template everywhere start to showing up this first line

expr:id="post-" +data:post.id">

what i did to solve this just find again whole block of code and delete that line that was showing and all workd now :-) Thank

Come and see http://footballvideoclip.blogspot.com

August 15, 2009 at 6:30 AM Brent said...

Hi and thanks for a good solution... at least so far.

Something that may be useful for those pedants who, like me, just can't fathom someone having to find their place reading again... try this:

In the code that you paste into the post body div, there is a piece which forms the link to the fullpost page:

< a expr:href='data:post.url' >.

Instead, change it to this:

< a expr:href='data:post.url + & quot;#more& quot;' >

And just after the < span class="fullpost" > that you put before the hidden portion of your post, add:

< span id="more" >< /span >, and then continue your post as normal, with the final closing tag < /span > at the very end.

Your readers will no longer have to search for the place they left off reading.

Thanks again for a nice solution.

B.

Note: I've added spaces before and after the "&", "<", and ">" marks so that my post could be accepted. If you copy and paste be sure to remove those spaces!

August 18, 2009 at 8:19 AM
Louie said...

wow you are really a lot of help for us newbie bloggers specially in using blogspot you have to learn some tweaks thx a lot!

August 19, 2009 at 3:24 AM Brad Hill said...

I have a static home page and do not want summary posts. How can I use this hack, but change it to only apply to label and archive pages? I have searched Google but have found nothing. Mahalo for all of your posts. They have assisted me greatly on all of my sites.

August 26, 2009 at 8:41 AM Sterferson Luiz said...

USEFULL!!! You're the best!

September 1, 2009 at 11:02 PM David Chambers said...

i added summaries to a new website, "whittaker chambers in books" (http://wcinbooks.whittakerchambers.org/). the summaries work fine with internet explorer and firebox (pc/mac) but "erratically" (usually) not with google's browser on pc, with safari (pc/mac) and with icab (mac). any ideas why i'm getting hit-and-miss?...

Post a Comment