最近我的博客Sample批准了 Adsense,所以我开始将广告放在帖子的顶部。但这会导致广告代码显示在帖子摘要中,如下所示 请看这个
请帮我弄清楚如何删除它。
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 方法(在我们的示例中,这是完整的帖子内容)。设置选项linebreaks
和links
至false
需要完成从通过此运算符生成的代码片段中删除所有 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/