【问题标题】:How do I implement Schema.org markups on Shopify?如何在 Shopify 上实施 Schema.org 标记?
【发布时间】:2019-02-21 10:10:30
【问题描述】:

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

这是我所指的代码模板:

<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

在我无休止的研究中,我遇到了许多不同的网站和博客,它们告诉我只需将此 script 添加到 theme.liquid 文件中,但我找不到正确实施它的方法。 This is the blog post I was browsing

你们中有人有这方面的经验吗,或者我应该联系 Shopify 开发人员并让他来完成这项工作?

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

<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>

【问题讨论】:

    标签: shopify schema.org json-ld


    【解决方案1】:

    我不明白什么不适合你?

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

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

    这是一个完整的工作示例:

    <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>
    

    【讨论】:

    • 谢谢!正是我想要的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多