javascript - 脚本代码片段显示在博客文章摘要中

标签 javascript html blogger adsense

最近我的博客Sample批准了 Adsense,所以我开始将广告放在帖子的顶部。但这会导致广告代码显示在帖子摘要中,如下所示 请看这个ximagex

请帮我弄清楚如何删除它。

Java 脚本代码

<script type='text/javascript'>
//<![CDATA[
//Post Thumbnail Setting
var TemplateismSummary = {
    displayimages: false,
    imagePosition: 'left',
    Widthimg: 200,
    Heightimg: 0,
    noThumb: 'https://lh3.googleusercontent.com/-GRP8IcURRsw/T9MjiNWXUcI/AAAAAAAAB88/QEDpDHxI55o/s1600/no-thumb.jpg',
    SummaryWords: 21,
    wordsNoImg: 20,
    skipper: 0,
    DisplayHome: true,
    DisplayLabel: true
};

最佳答案

您将需要使用新引入的 snippet运算符(operator)。这是 Blogger 用于从 HTML 字符串生成片段的 native 方法(在我们的示例中,这是完整的帖子内容)。设置选项linebreakslinksfalse需要完成从通过此运算符生成的代码片段中删除所有 HTML 标签。替换<data:post.body/>的实例使用以下代码 -

<b:if cond='data:blog.pageType not in {"static_page", "item"}'>
  <b:eval expr='snippet(data:post.body, {length: 450, linebreaks: false, links: false})' />
<b:else/>
  <data:post.body/>
</b:if>

有关 snippet 的所有选项的信息运算符-

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.

关于javascript - 脚本代码片段显示在博客文章摘要中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41310207/

相关文章:

单击“提交”后,JavaScript 验证错误消息没有消失

Javascript。替换 Div 的 HTML 内容

HTML 响应不工作

javascript - 通过两个标签小部件作为下拉菜单在博客平台中搜索

jquery - 如何将短代码添加到 blogspot?

javascript - 是否可以获取 View 上每个 div 的坐标并将它们保存在 javascript onunload() 函数中的本地存储中?

javascript - 有人可以解释当用户在浏览器中输入 URL http ://www. it.brighton.ac.uk/index.html 时会发送什么请求消息

html - ServiceNow 服务门户 Flexbox

html - 从 Layout 组件对齐 Antd 的右菜单

html - 如何使网页内容的宽度达到 100%?