C0n*_*0nk 3 html microdata schema.org
所以我在看Schema.org.我需要将<html>标签更改为此标记吗?
<html itemscope itemtype="http://schema.org/Article">
Run Code Online (Sandbox Code Playgroud)
或者我可以只使用我的<head></head>块中的元标记?
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<meta itemprop="image" content="http://www.example.com/image.jpg">
Run Code Online (Sandbox Code Playgroud)
属性需要属于某个项目.您可以使用itemscope属性创建项目(该itemtype属性可以为此项目指定类型).
没有itemscope,您的标记示例无效.
可以仅在head元素内提供微数据,但不建议这样做有两个原因:
Microdata旨在用于您现有的标记.虽然在(包括,参见示例)中包含某些meta/ link元素通常是有意义的,但大多数内容通常都在.如果您只想使用其中的元素,则必须复制大部分内容.但是如果你想走那条路,你可能更喜欢使用JSON-LD.headitemrefbodyhead
由于head不允许使用分组元素(如div),表达微数据变得复杂.您必须使用itemref每个属性并滥用style每个项目的元素(请参阅此答案中的第一个片段作为示例).
您的示例可能如下所示:
<head>
<style itemscope itemtype="http://schema.org/Article" itemref="p1a p1b p1c"></style>
<meta id="p1a" itemprop="name" content="The Name or Title Here">
<meta id="p1b" itemprop="description" content="This is the page description">
<link id="p1c" itemprop="image" href="http://www.example.com/image.jpg">
</head>
Run Code Online (Sandbox Code Playgroud)
如果你可以itemscope在head元素上使用,那会更好:
<head itemscope itemtype="http://schema.org/Article">
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<link itemprop="image" href="http://www.example.com/image.jpg">
</head>
Run Code Online (Sandbox Code Playgroud)
但只要你需要一个以上的项目(这通常是这种情况,例如,针对Organization/ Person这是author等),这不工作了,你就需要在我的第一个片段的溶液等.
请注意,允许在元素中使用微元数据meta/ link元素body.这样可以更容易,因为您可以使用div元素itemscope.因此,即使您复制内容而不是标记现有内容,最好在以下位置执行此操作body:
<div itemscope itemtype="http://schema.org/Article">
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<link itemprop="image" href="http://www.example.com/image.jpg">
</div>
Run Code Online (Sandbox Code Playgroud)
(I替换meta为元素image与属性link元件,因为使用meta是用于该目的无效.)
Whatwg.org上有关微数据的部分没有明确提及 HTML 文档的 -element中的 -elements 。总之,您需要有有效的标记。metaheaditemscope
如果您查看schema.org上的描述,您会发现有关网页的部分:
\n\n\n\n\n每个网页都被隐式地假定为声明为 WebPage 类型,因此可以使用有关该网页的各种属性,例如面包屑。如果指定了这些属性,我们建议显式声明,但如果在项目范围之外找到它们,则将假定它们与页面有关。
\n
有趣的部分是:
\n\n\n\n\n[\xe2\x80\xa6] 如果在 之外找到它们[属性]
\nitemscope,则将假定它们与页面有关。
据此,您不需要itemscope- 元素html。但它读起来更像是一个建议,而不是一个明确的规范。
您也可以在 Google 的结构化数据测试工具中看到此行为。当您运行此代码时:
\n\n<!DOCTYPE html>\n<html lang="en">\n <head>\n <meta itemprop="name" content="The Name or Title Here">\n <meta itemprop="description" content="This is the page description">\n <meta itemprop="image" content="http://www.example.com/image.jpg">\n </head>\n</html>\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x80\xa6 你会发现它没有捕获任何数据。一旦您添加itemscope导致未指定类型且没有任何错误,它将开始捕获数据:
使用itemtype="http://schema.org/Article"将失败或至少抛出错误,因为为 type 提供的属性太少Article。
所有不同的类型都可以在scheme.org 的网页概述中找到。也许一个适合整个页面。
\n