使用 HTML5 Microdata 的中的标签

发布于 2024-12-02 19:08:58 字数 607 浏览 3 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

月寒剑心 2024-12-09 19:08:58

meta 标签不能与这样的 itemscope 一起使用。表达这一点的正确方法是通过使用 link 标记的规范引用:

<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>
    <link itemprop="availability" href="http://schema.org/InStock">
  </dl>
</div>

The meta tag can't be used with an itemscope like that. The correct way to express this is through a canonical reference using the link tag:

<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>
    <link itemprop="availability" href="http://schema.org/InStock">
  </dl>
</div>
时光礼记 2024-12-09 19:08:58

我做了与OP相同的事情并得到了相同的结果,其中测试工具的可用性链接到一个子项目...我终于能够通过以下方式正确验证它:

<meta itemprop='availability' content='http://schema.org/InStock'>

这是Google结构化工具输出对于报价:

Item 1
type:   http://schema.org/offer
property:   
price:  Price: $139.00
pricecurrency:  USD
availability:   http://schema.org/InStock

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:

<meta itemprop='availability' content='http://schema.org/InStock'>

Here is the Google structured tool output for the offer:

Item 1
type:   http://schema.org/offer
property:   
price:  Price: $139.00
pricecurrency:  USD
availability:   http://schema.org/InStock
海风掠过北极光 2024-12-09 19:08:58

虽然允许中使用meta(如果用于微数据!) body,您的示例由于以下几个原因不正确:

  • dl 元素只能包含 dtdd (并且script/template)元素。您必须将 meta 放置在 dt/dd 内部,或者放置在 dl 外部(但是随后您将必须移动 itemscope)。

  • meta 元素必须具有 content 属性。

  • 为此目的使用 itemid 是不正确的,并且 http://schema.org/ItemAvailability 不是类型,因此使用 itemscope >+itemtype 也不正确。

  • 但是,如果 itemprop 值是 URI,则您必须使用link 元素而不是 meta 元素。

此外,price 值不应包含货币符号,并且您的 dt 似乎实际上应该是 dd (带有 dt 包含“价格”或其他内容)。

所以你可以使用:

<dl itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  <dt>Price</dt>
  <dd>
lt;span itemprop="price">1</span> <link itemprop="availability" href="http://schema.org/InStock" /></dd>
</dl>

While it is allowed to use meta (if used for Microdata!) in the body, your example is not correct for several reasons:

  • The dl element can only contain dt or dd (and script/template) elements. You either have to place the meta inside of dt/dd, or outside of dl (but then you would have to move the itemscope).

  • The meta element must have a content attribute.

  • Using itemid for this purpose is not correct, and http://schema.org/ItemAvailability is not a type, so using itemscope+itemtype isn’t correct either.

  • However, if the itemprop value is a URI, you must use the link element instead of the meta element.

Furthermore, the price value should not contain a currency symbol, and it seems that your dt should actually be a dd (with a dt containing "Price" or something).

So you could use:

<dl itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  <dt>Price</dt>
  <dd>
lt;span itemprop="price">1</span> <link itemprop="availability" href="http://schema.org/InStock" /></dd>
</dl>
空城仅有旧梦在 2024-12-09 19:08:58

我在这里做了一个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:

enter image description here

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.

我只土不豪 2024-12-09 19:08:58

请参阅“不可见内容”标题下的内容(不确定这是否有帮助):

Google 网站站长工具- 关于微数据

一般来说,Google 不会显示用户不可见的内容。换句话说,不要以一种方式向用户展示内容,而使用隐藏文本分别为搜索引擎和Web应用程序标记信息。您应该标记用户访问您的网页时实际显示的文本。

本指南有一些例外情况。在某些情况下,向搜索引擎提供更详细的信息可能很有价值,即使您不希望页面访问者看到该信息。例如,如果一家餐厅的评分为 8.5,则用户(而非搜索引擎)将假定该评分基于 1-10 的等级。在这种情况下,您可以使用元元素来指示这一点,如下所示:


评分:8.5
>

See under the heading Non-visible content (not sure if this helps):

Google webmaster tools - About microdata

In general, Google won't display content that is not visible to the user. In other words, don't show content to users in one way, and use hidden text to mark up information separately for search engines and web applications. You should mark up the text that actually appears to your users when they visit your web pages.

There are a few exceptions to this guideline. In some situations it can be valuable to provide search engines with more detailed information, even if you don't want that information to be seen by visitors to your page. For example, if a restaurant has a rating of 8.5, users (but not search engines) will assume that the rating is based on a scale of 1–10. In this case, you can indicate this using the meta element, like this:

<div itemprop="rating" itemscope itemtype="http://data-vocabulary.org/Rating">
Rating: <span itemprop="value">8.5</span>
<meta itemprop="best" content="10" />
</div>

好倦 2024-12-09 19:08:58

这是 schema.org 入门指南中的一个示例,用于支持 @Lawrence 的答案。

但是,我不喜欢在页面正文中使用链接标记。来自 MDN

链接标签只能出现在 head 元素中;

是否有更好的方法使用有效标记来指定可用性?

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:

A link tag can occur only in the head element;

Isn't there a better way of specifying availability using a valid markup?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文