如何使用微数据在ItemPage上表示类似产品?

问题描述 投票:0回答:1

我正在尝试使用Microdata通过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验证代码时,相似产品部分显示为单独的节点,而不是ItemPage的一部分。

ItemPage

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

html microdata
1个回答
0
投票

解决方案1:嵌套

您可以在主要产品中添加

isSimilarTo

解决方案2:<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>

如果无法将类似产品嵌套在主要产品的HTML元素下,则可以使用Microdata的itemrefitemref)。

解决方案3:ID

((仅当不可能使用解决方案1或2时,才应采用这种方式,因为并非所有消费者都将支持此解决方案3。]

类似于您当前正在使用的产品,您可以给主产品一个URI作为标识符(具有Microdata的example属性,并引用该URI作为类似产品中itemid的值。

isSimilarTo
© www.soinside.com 2019 - 2024. All rights reserved.