如何使用Microdata的'itemref'引用产品范围之外列出的类似产品?

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

我正在尝试使用Schema.org定义使用Microdata定义我的网站。在ItemPage上,我正在显示有关产品的信息。此外,我想在相关产品显示在当前产品范围之外时单击ItemPage

我试图使用link similar products to the current product属性来实现这一目标。但是,当我查看itemref上的页面时,它没有显示相关产品属于itemref节点的一部分。

Structured Data Testing Tool
html schema.org microdata
1个回答
1
投票

必须以其他方式使用:

  • ItemPage属性必须位于表示要向其添加属性的项目的元素上。这将是您的主要产品。

  • 您要添加的元素需要<body itemscope itemtype="http://schema.org/ItemPage"> <header itemprop="hasPart" itemscope itemtype="http://schema.org/WPHeader"> </header> <article itemprop="mainEntity" itemscope itemtype="http://schema.org/Product" id="details_10"> <h2 itemprop="name">Product 10</h2> </article> <aside> <article itemref="details_10" itemscope itemtype="http://schema.org/Product"> <h3 itemprop="name">Product 20</h3> </article> <article itemref="details_10" itemscope itemtype="http://schema.org/Product"> <h3 itemprop="name">Product 30</h3> </article> </aside> <footer itemprop="hasPart" itemscope itemtype="http://schema.org/WPFooter"> </footer> </body> 属性(缺少itemref属性),以及需要itemprop属性引用的isSimilarTo。在您的情况下,这些将是类似的产品。

所以,这将给:

id

此标记的问题是,两个itemref属性也被添加到<body itemscope itemtype="http://schema.org/ItemPage"> <article itemprop="mainEntity" itemscope itemtype="http://schema.org/Product" itemref="details_20 details_30"></article> <aside> <article id="details_20" itemprop="isSimilarTo" itemscope itemtype="http://schema.org/Product"></article> <article id="details_30" itemprop="isSimilarTo" itemscope itemtype="http://schema.org/Product"></article> </aside> </body> (因为它们嵌套在它的下面),这是不正确的。为了避免这种情况,最好的解决方案是不在isSimilarTo元素上指定ItemPage,而在ItemPage或类似元素上指定。

body

((您也可以使用div来避免将主<body> <div itemscope itemtype="http://schema.org/ItemPage"> <article itemprop="mainEntity" itemscope itemtype="http://schema.org/Product" itemref="details_20 details_30"></article> </div> <aside> <article id="details_20" itemprop="isSimilarTo" itemscope itemtype="http://schema.org/Product"></article> <article id="details_30" itemprop="isSimilarTo" itemscope itemtype="http://schema.org/Product"></article> </aside> </body> 嵌套在itemref下。例如,这也可以在Product元素上指定ItemPage。)

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