问题
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 overcome those two issues.
回答1:
You 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.
回答2:
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.
回答3:
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>
来源:https://stackoverflow.com/questions/34963026/how-to-increase-character-lengh-in-blogger-snippet-instead-of-using-limited-leng