首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Shopify上实现Schema.org标记?

如何在Shopify上实现Schema.org标记?
EN

Stack Overflow用户
提问于 2019-02-21 10:10:30
回答 1查看 765关注 0票数 1

我最近开始为一家美容公司工作,该公司希望为他们的产品页面实现丰富的片段。我知道Schema.org标记是如何工作的,因为我复制了我朋友在一家移动应用程序开发公司中使用的通用Organization标记。

下面是我指的代码模板:

代码语言:javascript
运行
复制
<script type="application/ld+json">
 { "@context": "http://schema.org",
 "@type": "Organization",
 "name": "Company name",
 "legalName" : "Legal Name",
 "url": "Company URL",
 "logo": "internal logo link",
 "foundingDate": "founding date",
 "founders": [
 {
 "@type": "Person",
 "name": "Founder"
 } ],
 "address": {
 "@type": "PostalAddress",
 "streetAddress": "Street Address",
 "addressLocality": "City",
 "addressRegion": "Region",
 "postalCode": "Postcode",
 "addressCountry": "United Kingdom"
 },
 "contactPoint": {
 "@type": "ContactPoint",
 "contactType": "customer support",
 "telephone": "Phone Number",
 "email": "email contact"
 },
 "sameAs": [ 
 "Social Media Links"
 ]}
</script>

对我来说不幸的是,这家公司的网站是Shopify-based.

在我没完没了的研究中,我遇到了许多不同的站点和博客,它们告诉我简单地将这个script添加到theme.liquid文件中,但是我找不到正确实现它的方法。这是我浏览的博客文章。

你们中有谁有这方面的经验吗,或者我应该联系Shopify开发人员让他做这件事吗?

我已经尝试使用这个代码模板(我只是将其复制并粘贴在液体文件中):

代码语言:javascript
运行
复制
<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Product",
  "name": "{{ product.title }}",
  "sku": "{{ product.variants.first.sku }}",
  "gtin14": "{{ product.variants.first.barcode }}",
  "brand": "{{ product.vendor }}",
  "description": "{{ product.description | strip_html | escape }}",
  "image": "https:{{ product.featured_image.src | img_url: 'grande' }}",
    "offers": {
        "@type": "Offer",
        "priceCurrency": "{{ shop.currency }}",
        "price": "{{ product.price |money_without_currency  | strip_html }}",
        "itemCondition" : "http://schema.org/NewCondition",
        "availability" : "{% if product.available == true %}http://schema.org/InStock{% else %}http://schema.org/OutOfStock{% endif %}",
        "url" : "{{ shop.url }}{{ product.url }}"
    }
}
</script>
EN

Stack Overflow用户

发布于 2019-02-22 14:24:02

我不明白什么不适合你?

如文章所述,将其放入theme.liquid文件中。

但是,不只是放置产品模式(如果不在产品模板上)将导致大量错误,因为{{ product.title }}不会呈现任何内容;使用template if语句来获得索引、产品和文章的结果。

下面是一个完整的、实用的示例:

代码语言:javascript
运行
复制
<script type="application/ld+json">
{%- if template == 'index' -%}
{
  "@context": "http://schema.org",
  "@type": "WebSite",
  "name": "{{ shop.name }}",
  "alternateName": "{{ shop.description }}",
  "url": "{{ shop.url }}"
}
{%- elsif template == 'product' %}
{
  "@context": "http://schema.org",
  "@type": "Product",
  "description": "{{ product.description | strip_html }}",
  "name": "{{ product.title }}",
  "image": "{{ product.featured_image | img_url: 'master' }}",
  "manufacturer": "{{ product.vendor }}",
  "category": "{{ collection.title }}",
  "sku": "{{ product.selected_or_first_available_variant.sku }}",
  "url": "{{ shop.url | append: product.url }}",
  "offers": {
    "@type": "Offer",
    "availability": "InStock",
    "price": "{{ product.price | money_without_currency }}",
    "priceCurrency": "{{ shop.currency }}"
  }
}
{%- elsif template == 'article' %}
{
  "@context": "http://schema.org",
  "@type": "NewsArticle",
  "image": {
    "@type": "imageObject",
    "url": "https:{{ article.image.src | img_url: 'original' }}",
    "width": "1024px",
    "height": "1024px"
  },
  "keywords": "{%- for tag in article.tags -%}{{ tag }}{%- unless forloop.last -%}, {%- endunless -%}{%- endfor -%}",
  "url": "{{ shop.url | append: article.url }}",
  "description": "{{ article.content | truncatewords: 100 | strip_html }}",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://google.com/article"
  },
  "headline": "{{ article.title }}",
  "datePublished": "{{ article.published_at }}",
  "dateModified": "{{ article.published_at }}",
  "author": {
    "@type": "Person",
    "name": "{{ article.author }}"
  },
  "publisher": {
    "@type": "Organization",
    "name": "{{ shop.name }}",
    "logo": {
      "@type": "ImageObject",
      "url": "{{ shop.url }}"
    }
  },
  "commentCount": "{{ article.comments_count }}"
}
{%- endif %}
</script>
票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54804445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档