How can I create expandable post summaries or "Read more" links on their blog's index page

Many users have been asking for an easy way to implement "Read more" links on their blog's index page. In fact, for years bloggers have been implementing "Read more" jump breaks themselves by manually editing their HTML --- a process that was complicated and error prone. 


With this trick, you can choose to display an arbitrary amount of text from the beginning of each post, as a teaser for the whole thing. Then users who want to read the rest of the post can click a link to see the full text. This is handy if you have lots of long articles all on one page. Note that you'll need to have post pages enabled in order to make this feature work.
There are three ingredients that go into this feature: conditional CSS, a "read more" link for each post, and a modification for the posts that use this feature. So let's go through it step by step.

Conditional CSS

We're going to use conditional tags to change how posts display on different pages. Add the following code to your style sheet, depending on what kind of template you have:
(for classic templates)
<MainOrArchivePage> 
span.fullpost {display:none;}
</MainOrArchivePage>

<ItemPage>
span.fullpost {display:inline;}
</ItemPage>

(for layouts)

<b:if cond='data:blog.pageType == "item"'> 
span.fullpost {display:inline;}
<b:else/>
span.fullpost {display:none;}
</b:if>
Note: Before making any changes to your HTML, you will need to make sure that the'Expand Widget Templates' option is selected.
Your style sheet is usually near the top of your template, between the <style> and</style> tags. If you have your style sheet in a separate file, you'll still need to add these lines in your template, so the conditional tags will work. Just make sure you add in the <style> tags around them.
What we did here was to define a class called "fullpost" that will appear only on post pages (permalinks). Part of each post will use this class, as we'll see later.

"Read More" Links

Add the following code to your template, somewhere after the <$BlogItemBody$>or <data:post.body/> tag:
(for classic templates)
<MainOrArchivePage><br />
<a href="<$BlogItemPermalinkURL$>">Read more!</a>
</MainOrArchivePage>

(for layouts)

<b:if cond='data:blog.pageType != "item"'><br />
<a expr:href='data:post.url'>Read more!</a>
</b:if>
This link will only appear on the main page and archive pages, and it will redirect your reader to the post page containing the full text of your post. You can replace the "Read more!" text with whatever you like, of course.

Post Modifications

The final piece that we need is a little bit of code in your actual post. Each post that you want to use this feature on will need this code:
<span class="fullpost"></span>
This part can actually go in the post template, if you don't want to have to type it for each post. You'll enter the summary text outside the span tags and the remainder inside, like so:
Here is the beginning of my post. <span class="fullpost">And here is the rest of it.</span>
Now, when a reader visits your blog, this post will appear like this:
Here is the beginning of my post.
Read more!
When they click the link, they'll go to the post page where they'll see the whole thing:
Here is the beginning of my post. And here is the rest of it.

With Jump Breaks you can show just a snippet of your post on your blog's index page. Blogger will insert a "Read more" link to the full post page where your readers can keep reading.




There are a couple of ways to insert a "Read more" jump to your posts. If you use the new post editor , you'll notice the "Insert jump break" icon in the editor's toolbar. Click this icon and the "jump break" will be inserted into your blog post at your cursor's position.



If you don't use the new post editor, you can still insert a jump break in Edit HTML mode by adding <!-- more --> where you want to position the jump break.



Want to change the "Read more" text to something more your style? No problem. You can edit the "Read more" text by clicking Layout and then Edit the Blog Posts widget.


One more note, the Jump Break feature does not change how your post appears in your feed. You can configure post feed options by going to Settings | Basic | Site Feed, and editing Allow Blog Feeds.

Update
: Users that have customized their Blog Posts widget or otherwise have highly customized templates: You may need to edit your HTML to enable Jump Breaks. First, back up your template, then follow the instructions at the bottom of this help article.

Notes:
  • As with any template modifications, you should be sure to save a backup copy of your template before you start. Just copy and paste all your code to a text file on your hard drive, so you'll have it there as a replacement in case anything goes wrong.
  • An alternative to creating post excerpts like this is to use the show/hide method on entire posts. Each method has its own advantages and disadvantages.
  • Advantages to this method: Customizable summaries, rather than titles only. Can be applied to some posts and not others (for instance, you might only want this for your longer posts).
  • Disadvantages: Requires changes to the posts themselves, rather than to the template only. However, the "read more" link is in the template, so it will appear regardless of whether a post has been truncated or not. (Modifying this feature is left as an exercise for the reader.)
0 Comments
Disqus
Fb Comments
Comments :

0 comments:

Post a Comment