使用 HTML5 Microdata 的中的标签
我想使用 HTML5+Microdata 的 标记使用 Schema 指定产品是否“有货” .org。
我不确定这是否是正确的语法:
<div itemscope itemtype="http://schema.org/Product">
<h2 itemprop="name">Product Name</h2>
<dl itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<dt itemprop="price">$1</dt>
<meta itemprop="availability" itemscope itemtype="http://schema.org/ItemAvailability" itemid="http://schema.org/InStock">
</dl>
</div>
I want to specify if the Product is "In Stock" using HTML5+Microdata's <meta>
tag using Schema.org.
I am unsure if this is the correct syntax:
<div itemscope itemtype="http://schema.org/Product">
<h2 itemprop="name">Product Name</h2>
<dl itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<dt itemprop="price">$1</dt>
<meta itemprop="availability" itemscope itemtype="http://schema.org/ItemAvailability" itemid="http://schema.org/InStock">
</dl>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
meta
标签不能与这样的 itemscope 一起使用。表达这一点的正确方法是通过使用link
标记的规范引用:The
meta
tag can't be used with an itemscope like that. The correct way to express this is through a canonical reference using thelink
tag:我做了与OP相同的事情并得到了相同的结果,其中测试工具的可用性链接到一个子项目...我终于能够通过以下方式正确验证它:
这是Google结构化工具输出对于报价:
I did the same as the OP and got the same thing, where the availability on the testing tool is linked to a sub-item... I was finally able to get it to verify properly with this:
Here is the Google structured tool output for the offer:
虽然允许在
中使用
,您的示例由于以下几个原因不正确:meta
(如果用于微数据!) bodydl
元素只能包含dt
或dd
(并且script
/template
)元素。您必须将meta
放置在dt
/dd
内部,或者放置在dl
外部(但是随后您将必须移动itemscope
)。meta
元素必须具有content
属性。为此目的使用
itemid
是不正确的,并且http://schema.org/ItemAvailability
不是类型,因此使用itemscope
>+itemtype
也不正确。但是,如果
itemprop
值是 URI,则您必须使用link
元素而不是meta
元素。此外,
price
值不应包含货币符号,并且您的dt
似乎实际上应该是dd
(带有dt
包含“价格”或其他内容)。所以你可以使用:
While it is allowed to use
meta
(if used for Microdata!) in thebody
, your example is not correct for several reasons:The
dl
element can only containdt
ordd
(andscript
/template
) elements. You either have to place themeta
inside ofdt
/dd
, or outside ofdl
(but then you would have to move theitemscope
).The
meta
element must have acontent
attribute.Using
itemid
for this purpose is not correct, andhttp://schema.org/ItemAvailability
is not a type, so usingitemscope
+itemtype
isn’t correct either.However, if the
itemprop
value is a URI, you must use thelink
element instead of themeta
element.Furthermore, the
price
value should not contain a currency symbol, and it seems that yourdt
should actually be add
(with adt
containing "Price" or something).So you could use:
我在这里做了一个jsfiddle:http://jsfiddle.net/dLryX/,然后输入输出(< a href="http://jsfiddle.net/dLryX/show/" rel="nofollow noreferrer">http://jsfiddle.net/dLryX/show/) 进入丰富网页摘要 工具。
返回:
我相信语法是正确的,并且警告并不重要,因为它没有属性,因为它是元标记。
I made a jsfiddle here: http://jsfiddle.net/dLryX/, then put the output (http://jsfiddle.net/dLryX/show/) into the rich snippets tool.
That came back with:
I believe the syntax is correct, and that the Warning isn't important, as it doesn't have a property, as it's a meta tag.
请参阅“不可见内容”标题下的内容(不确定这是否有帮助):
Google 网站站长工具- 关于微数据
See under the heading Non-visible content (not sure if this helps):
Google webmaster tools - About microdata
这是 schema.org 入门指南中的一个示例,用于支持 @Lawrence 的答案。
但是,我不喜欢在页面正文中使用链接标记。来自 MDN:
是否有更好的方法使用有效标记来指定可用性?
This is an example from schema.org's getting started guide to support @Lawrence's answer.
However, I don't like the use of the link tag inside the body of the page. From MDN:
Isn't there a better way of specifying availability using a valid markup?