用于Google文章Rich Snippet的带有'mainEntityOfPage'的Microdata标记 [英] Microdata markup with 'mainEntityOfPage' for Google Article Rich Snippet

查看:170
本文介绍了用于Google文章Rich Snippet的带有'mainEntityOfPage'的Microdata标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google的文章Rich Snippet的 Microdata示例包含此 meta 元素与Schema.org的 mainEntityOfPage 属性:

The Microdata example of Google’s Article Rich Snippet contains this meta element with Schema.org’s mainEntityOfPage property:


<meta itemscope itemprop="mainEntityOfPage"  itemType="https://schema.org/WebPage" itemid="https://google.com/article"/>


当使用 Nu Html Checker ,我收到此错误:

When checking it with the Nu Html Checker, I get this error:


元素缺少必需属性内容

添加一个空的内容属性似乎解决了这个错误。这样做是正确的吗?

Adding an empty content attribute seems to solve this error. Is it correct to do this?

推荐答案

Nu Html Checker是正确的,Google的示例是无效的。如果 meta 元素具有 itemprop ,则需要 content 属性>属性。

The Nu Html Checker is correct, Google’s example is invalid. The content attribute is required if the meta element has an itemprop attribute.

WHATWG HTML 以及 HTML 5.1(W3C工作草案):如果指定了[...] itemprop ,那么内容属性也必须指定。

从旧的 Microdata(W3C Note):如果 meta 元素具有 itemprop 属性, content 属性必须存在。

From WHATWG HTML and also HTML 5.1 (W3C Working Draft): "If […] itemprop is specified, then the content attribute must also be specified."
From the old Microdata (W3C Note): "If a meta element has an itemprop attribute, […] the content attribute must be present."

添加一个空的内容属性使其有效,但也有其他选择。

Adding an empty content attribute makes it valid, but there are also other options.

Schema.org的 mainEntityOfPage 属性期望值为URL或 CreativeWork 项。

Schema.org’s mainEntityOfPage property expects as value either a URL or a CreativeWork item.

Google自己的的推荐/必需属性表示他们期望URL值,但他们的示例显示了如何创建项目值。

Google’s own documentation for the recommended/required properties for their Article Rich Snippet says that they expect a URL value, but their examples show how to create an item value.

根据 Google结构化数据测试工具。 (一些示例使用 itemid 属性,严格地说,尚未允许/定义。)

All of the following solutions are fine according to the Google Structured Data Testing Tool. (Some examples use the itemid attribute, which is, strictly speaking, not yet allowed/defined for the Schema.org vocabulary.)

<link itemprop="mainEntityOfPage" href="https://example.com/article" />

直截了当。

建议,需要最少的标记,并且在以及 body 中工作。

This follows Google’s own recommendation, requires minimal markup, and works in the head as well as the body.

如果您有可见链接,您当然也可以使用 a 元素。

If you have a visible link, you can of course also use an a element.

作为类型,您可以使用 CreativeWork 或其任何子类型,例如 WebPage

As type you can use CreativeWork or any of its subtypes, like WebPage.

<div itemprop="mainEntityOfPage" itemscope itemtype="http://schema.org/WebPage">
  <link itemprop="url" href="https://example.com/article" /> 
</div>

这会创建一个 WebPage code> url 属性。它只能用于 body

This creates a WebPage item with a url property. It can only be used in the body.

如果您有可见的链接,当然也可以使用一个 a 元素。

If you have a visible link, you can of course also use an a element.

<meta itemprop="mainEntityOfPage" content="" itemscope itemtype="http://schema.org/WebPage" itemid="https://example.com/article" />

这是基于Google的例子,但有一个空的 content 属性使其有效。

This is based on Google’s example, but with an empty content attribute to make it valid.

请注意,Microdata解析器必须忽略内容属性情况,因为提供了 itemscope 属性( Microdata W3C Note / WHATWG HTML Microdata :第一个匹配案例)。所以 itemprop 值将是一个项目,而不是一个字符串。

Note that Microdata parsers have to ignore the content attribute in that case, because the itemscope attribute is provided (Microdata W3C Note/WHATWG HTML Microdata: "first matching case"). So the itemprop value will be an item, not a string.

这会创建一个带有标识符的空项目。适用于以及正文。它不允许将属性直接添加到此 WebPage 项目中(您必须使用相同的 itemid

div 元素包含 itemid



This creates an empty item with an identifier. Works in the head as well as the body. It doesn’t allow to add properties directly to this WebPage item (you’d have to create another item with the same itemid value).

<div itemprop="mainEntityOfPage" itemscope itemtype="http://schema.org/WebPage" itemid="https://example.com/article">
</div>

这会创建一个带有标识符的空项。而不是 meta 例子,它只能在 body 中工作,但是允许直接在这个 WebPage 项目。

This creates an empty item with an identifier. Instead of the meta example, it only works in the body, but therefore allows to add additional properties directly to this WebPage item.

如果您已在网页上提供网页项目,例如

If you already provide a WebPage item on your page, e.g.,

<body itemscope itemtype="http://schema.org/WebPage">

  <article itemscope itemtype="http://schema.org/Article">
  </article>

</body>

您可以通过Microdata的 itemref 属性:

you can make use of it via Microdata’s itemref attribute:

<body itemprop="mainEntityOfPage" itemscope itemtype="http://schema.org/WebPage" id="this-page">

  <article itemscope itemtype="http://schema.org/Article" itemref="this-page">
  </article>

</body>

结合上述方法之一,例如, itemid url 属性。

combined with one of the methods described above, e.g., with itemid or a url property.

请注意,您通常会使用反向属性 mainEntity ,但谷歌没有记录他们' d目前支持Rich Rich Snippet。

Note that you’d typically use the inverse property mainEntity in such a case, but Google doesn’t document that they’d support it for the Article Rich Snippet, currently.

这篇关于用于Google文章Rich Snippet的带有'mainEntityOfPage'的Microdata标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆