You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Blogger模板的Google结构化数据JSON中使用if else判断

你当前的写法不符合Blogger模板语法规则,将条件逻辑作为JSON属性写入会导致结构化数据校验失败,正确实现方式如下:

"image": {
        "@type": "ImageObject",
        "width": 1920,
        "height": 1080,
        "url": "<b:if cond='data:post.firstImageUrl'><data:post.firstImageUrl/><b:else/>https://example.com/logo.png</b:if>",
        "caption": "<data:post.title/>"
}

补充说明:

  • 该写法使用Blogger原生<b:if>条件标签在模板渲染阶段直接输出符合条件的url值,最终生成的JSON无多余属性,完全符合Google结构化数据规范
  • 如需要严格过滤空字符串场景,可将判断条件调整为<b:if cond='data:post.firstImageUrl and data:post.firstImageUrl != ""'

内容的提问来源于stack exchange,提问作者0x00000dead

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 04:24:01