如何在ItemPage上用Microdata表示相似的商品?

How to use Microdata to represent similar products on the ItemPage?

我正在尝试使用微数据使用 Schema.org 定义来定义我的网站。

下面是我当前的 HTML 标记:

<body itemscope itemtype="http://schema.org/ItemPage">
<link itemprop="url" href="https://example.com/i/10" />

<main role="main">

    <!-- Show the main product of the page -->           
    <div itemprop="mainEntity" itemtype="http://schema.org/Product" itemscope>
        <meta itemprop="name" content="My Main Product 10 Name" />
        <!-- ... more properties that describes current product -->   
    </div>


    <!-- List of 10 similar product the current product being viewed -->
    <div class="list-related-products">

        <div itemtype="http://schema.org/Product" itemscope>
            <meta itemprop="name" content="Related Product 20 Name" />
            <meta itemprop="url" content="https://example.com/i/20" />
            <div itemprop="isSimilarTo" itemscope itemtype="http://schema.org/Product">
                <link itemprop="url" href="https://example.com/i/10" />
            </div>
            <!-- ... more properties -->   
        </div>

        <!-- ... more products -->   
    </div>
</main>

</body>

当我使用 Structured Data Testing Tool, the similar products section shows up as a separate nodes and not part of the ItemPage 验证代码时。

如何在当前定义的产品下正确列出相关的相似产品?

解决方案 1:嵌套

您可以在主产品中添加isSimilarTo

<article itemprop="mainEntity" itemscope itemtype="http://schema.org/Product">
  <h2 itemprop="name">Product 10</h2>

  <aside>
    <article itemprop="isSimilarTo" itemscope itemtype="http://schema.org/Product">
      <h3 itemprop="name">Product 20</h3>
    </article>

    <article itemprop="isSimilarTo" itemscope itemtype="http://schema.org/Product">
      <h3 itemprop="name">Product 30</h3>
    </article>
  </aside>

</article>

解决方案 2:itemref

如果您无法将相似产品嵌套在主要产品的 HTML 元素下,您可以使用 Microdata 的 itemref (example).

方案三:ID

(只有当解决方案 1 或 2 不可行时,您才应该采用这种方式,因为并非所有消费者都会支持此解决方案 3。)

与您当前使用的类似,您可以为主要产品提供一个 URI 作为标识符(使用 Microdata 的 itemid 属性)并将此 URI 引用为类似产品中 isSimilarTo 的值产品。

<article itemprop="mainEntity" itemscope itemtype="http://schema.org/Product" itemid="https://example.com/i/10#this">
  <h2 itemprop="name">Product 10</h2>
</article>

<aside>
  <article itemscope itemtype="http://schema.org/Product">
      <h3 itemprop="name">Product 20</h3>
      <link itemprop="isSimilarTo" href="https://example.com/i/10#this" />
  </article>

  <article itemscope itemtype="http://schema.org/Product">
      <h3 itemprop="name">Product 30</h3>
      <link itemprop="isSimilarTo" href="https://example.com/i/10#this" />
  </article>
</aside>