如何使用 Microdata 的“itemref"来引用产品范围之外列出的类似产品? [英] How to use Microdata's 'itemref' to reference similar products that are listed outside of the Product scope?
问题描述
我正在尝试使用 Microdata 使用 Schema.org 定义来定义我的网站.在 ItemPage
上,我正在显示有关产品的信息.此外,我想将类似产品链接到当前产品,而相关产品正在当前产品的范围之外展示.
我尝试使用 itemref 来实现这一点
属性.但是,当我查看 结构化数据测试工具 它不显示相关产品是 ItemPage
节点的一部分.
<header itemprop="hasPart" itemscope itemtype="http://schema.org/WPHeader"></标题><article itemprop="mainEntity" itemscope itemtype="http://schema.org/Product" id="details_10"><h2 itemprop="name">产品 10</h2></文章><旁边><article itemref="details_10" itemscope itemtype="http://schema.org/Product"><h3 itemprop="name">产品 20</h3></文章><article itemref="details_10" itemscope itemtype="http://schema.org/Product"><h3 itemprop="name">产品 30</h3></文章></一边><footer itemprop="hasPart" itemscope itemtype="http://schema.org/WPFooter"></页脚>
必须反过来使用:
itemref
属性需要位于表示要向其添加属性的项目的元素上.这将是您的主要产品.您要添加的元素需要
itemprop
属性(您缺少该属性以及isSimilarTo
属性)和id
被itemref
属性引用.这些将是您案例中的类似产品.
所以,这将给出:
<article itemprop="mainEntity" itemscope itemtype="http://schema.org/Product" itemref="details_20 details_30"></article><旁边><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></一边>
这个标记的问题是两个 isSimilarTo
属性也被添加到 ItemPage
中(因为它们嵌套在它下面),这是不正确的.为避免这种情况,最好的解决方案不是在 body
元素上指定 ItemPage
,而是在 div
或类似元素上指定.
<div itemscope itemtype="http://schema.org/ItemPage"><article itemprop="mainEntity" itemscope itemtype="http://schema.org/Product" itemref="details_20 details_30"></article>
<旁边><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></一边>
(您也可以使用 itemref
来避免将主要 Product
嵌套在 ItemPage
下.这也允许指定 <例如,head
元素上的 code>ItemPage.)
I am trying to use Microdata to define my website using the Schema.org definitions. On an ItemPage
I am displaying the information about a product. Additionally, I want to link similar products to the current product while the related product is being displayed outside of the current product's scope.
I tried to achieve this using the itemref
attribute. However, when I review the page on Structured Data Testing Tool it does not show the related products are part of the ItemPage
node.
<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>
It has to be used the other way around:
The
itemref
attribute needs to be on the element that represents the item you want to add properties to. This would be the primary product in your case.The elements you want to add need the
itemprop
attribute (which you are missing, along with theisSimilarTo
property), and anid
that gets referenced by theitemref
attribute. These would be the similar products in your case.
So, this would give:
<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>
The problem with this markup is that the two isSimilarTo
properties get added to the ItemPage
, too (because they are nested under it), which would be incorrect. To avoid this, the best solution would be not to specify the ItemPage
on the body
element, but on a div
or similar.
<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>
(You could also use itemref
to avoid having to nest the primary Product
under the ItemPage
. This would also allow to specify the ItemPage
on the head
element, for example.)
这篇关于如何使用 Microdata 的“itemref"来引用产品范围之外列出的类似产品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!