最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to increase character lengh in blogger snippet instead of using limited length, 'data:post.snippet&

programmeradmin1浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 6

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.

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>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论