我改编了 http://schema.org/ItemList 上示例 2 中的代码
如何将其与产品
一起使用?在首页和其他一些页面上,我有一个产品列表,我希望对其有更好的标记。
下面的代码给出了错误
A value for the position field is required.
但是 Product
没有位置,因此如果 position
有值,则会给出不同的错误。
<ul itemscope itemtype="http://schema.org/ItemList">
<meta itemprop="numberOfItems" content="10" />
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/Product">
<!-- <meta itemprop="position" content="1" /> -->
<a href="#" itemprop="url">
<img src="asdf.jpg" itemprop="image">
<div class="product-list__title" itemprop="name">
Product name
</div>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<div itemprop="price">
$12
</div>
<link itemprop="availability" href="http://schema.org/InStock" />
</div>
</a>
</li>
</ul>
最佳答案
itemListElement
属性具有三个期望值:
列表项
文本
事物
ListItem
也是一个 Thing
,但它被显式列出是因为它在这里具有特殊的作用:ListItem
提供 position
属性(property)。如果您需要传达列表项的位置,则必须提供 ListItem
值。
请注意,并非每个 ItemList
都需要它。使用 Product
值的示例很好(除了 meta
元素不能是 ul
的子元素),除非您尝试为了获得 Google 丰富搜索结果的资格(这就是错误消息的含义),您可以保持这样。
如果您确实想提供位置,itemListElement
可能如下所示:
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<meta itemprop="position" content="1" />
<div itemprop="item" itemscope itemtype="http://schema.org/Product">
<!-- your Product -->
</div>
</li>
关于schema.org - 如何为 ItemList 中的产品编写标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50782676/