Joel Belton
Joel Belton

Reputation: 55

How to change blogger post snippet length without affecting other widget text?

In this code:

<div class='resumo'>
  <span><data:post.snippet/>
 </span>
</div>
<a class='read-more' expr:href='data:post.url'>Read More</a>

I replaced <data:post.snippet/> with <b:eval expr='snippet(data:post.body, {length: 450, linebreaks: false, links: false})' /> to try and increase character length on post snippet. It worked, but now the text in my other widgets are in bold or in italics. How do I change the snippet character length without affecting other widgets on my website?

Post snippet before replacing code:

Post snippet before replacing code:

Post snippet after replacing code (title, widget text, and more, has changed to italic):

Post snippet after replacing code:

Upvotes: 3

Views: 2301

Answers (1)

Prayag Verma
Prayag Verma

Reputation: 5651

This issue arose because data:post.body data tag contains the whole content of the post including the HTML unlike the data:post.snippet or data:post.longSnippet data tags which strip these away internally.

Even though the snippet operator only counts text content when determining the length but it doesn't explicitly strip away the HTML tags associated with that content (It only provides options for stripping away anchor (<a>) tags via the links option and <br> tags via linebreaks option but no options for other tags like bold or italics).

In this particular case, there is an HTML tag present for italicizing the text which couldn't be closed properly because of the character length limit of the snippet (In the screenshot, we can observe that the bold text from the post content is displaying correctly as the opening and closing tags were included within the snippet length itself). Due to the missing closing tag used for italicizing the text, the browser italicized all the text after the snippet (as it couldn't figure out where the italicizing should be stopped)

If the requirement for snippet length is not more than 850 characters, then using data:post.longSnippet would be a better choice than data:post.body. Previously data:post.longSnippet was limited to 300-400 characters but that limit has now been increased. Coupling it with the snippet operator would give you more control over the character length. The new code snippet would look like -

<b:eval expr='snippet(data:post.longSnippet, {length: 650, linebreaks: false, links: false})' />

Upvotes: 3

Related Questions