I'm currently using 'data:post.snippet' for blogger mobile snippet.
<div class='post-body' style='color:black;'>
<b:if cond='data:post.snippet'><data:post.snippet/></b:if>
</div>
But its character length(140) is too low, and it doesn't give a line break between the headings and paragraphs. When there's a heading at the very start line break is necessary. Can someone please suggest me a javascript code to replace above code to overe those two issues.
I'm currently using 'data:post.snippet' for blogger mobile snippet.
<div class='post-body' style='color:black;'>
<b:if cond='data:post.snippet'><data:post.snippet/></b:if>
</div>
But its character length(140) is too low, and it doesn't give a line break between the headings and paragraphs. When there's a heading at the very start line break is necessary. Can someone please suggest me a javascript code to replace above code to overe those two issues.
Share Improve this question asked Jan 23, 2016 at 11:43 slbgdpslbgdp 2231 gold badge4 silver badges11 bronze badges3 Answers
Reset to default 6You can utilize the data:post.longSnippet
data tag which has the limit of upto 300-400 character
<div class='post-body' style='color:black;'>
<b:if cond='data:post.snippet'><data:post.longSnippet/></b:if>
</div>
Otherwise, if you want to control the exact amount of text that you want to be visible in the snippet, then you can utilize the newly launched operator in the new themes
<div class='post-body' style='color:black;'>
<b:eval expr='snippet(data:post.body, {length: 450, links: false})' />
</div>
snippet(string, options)
Produces a short snippet from an HTML string.
options: Object specifying the snippeting options, which are:
links: boolean for whether to preserve anchors/links in the snippet. Defaults to true.
linebreaks: boolean for whether to preserve linebreaks (tags) in the snippet. Defaults to true.
ellipsis: boolean for whether to append an ellipsis (…) to the end of the snippet. Defaults to true.
length: Number specifying the maximum length of the snippet.
Change
<div class='post-body' style='color:black;'>
<b:if cond='data:post.snippet'><data:post.snippet/></b:if>
</div>
To
<div class='post-body' style='color:black;'>
<data:post.body/>
</div>
It will render your post body with proper HTML markup till any jump break (if exists) or otherwise the full post body.
Consider including jump breaks for all your posts, you can do it through the rich post editor or directly in the post HTML using the code <!--more-->
in the exact place where you want the break.
Javascript approaches are not mandatory to retreive post contents, Blogger natively do it.
I hope this is what you are looking for,
<div class='post-body' style='color:black;'>
<b:eval expr='snippet(data:post.body, {length: 200, links: false, linebreaks: false})' />
</div>