结构化数据(微数据)和嵌入式项目 [英] Structured data (microdata) and embedded items
问题描述
我想在Schema.org中使用Microdata来定义网页的主要内容,所以我做了这样的事情:
I want to use Microdata with Schema.org to define the main content of my webpage, so I did something like this:
<body itemscope="itemscope" itemtype="http://schema.org/WebPage">
...
<div itemprop="mainContentOfPage" itemscope="itemscope" itemtype="http://schema.org/WebPageElement">
<div itemprop="breadcrumb" itemscope="itemscope" itemtype="http://schema.org/BreadcrumbList">...</div>
</div>
...
</body>
问题是,当我在Google结构化数据测试工具下检查架构时,收到错误消息:
The problem is that when I check the schema under the Google Structured Data Testing Tool I receive the error:
对于类型为WebPageElement的对象,Google无法识别属性面包屑".
The property breadcrumb is not recognised by Google for an object of type WebPageElement.
那么怎么说breadcrumb
与WebPage
的itemscope
相关而不是与WebPageElement
的itemscope
相关?由于设计原因,我无法从WebPageElement
div
中获得breadcrumb
.
So how to say that the breadcrumb
is related to the itemscope
of the WebPage
and not to the itemscope
of the WebPageElement
? Because of the design, I can not get the breadcrumb
out of the WebPageElement
div
.
顺便说一句,在这里我以breadcrumb
为例,它可以是任何其他属性,例如copyrightHolder
或headline
.
By the ways, I use breadcrumb
just as an example here—it can be any other property, like copyrightHolder
or headline
, for example.
推荐答案
有一个丑陋的解决方案:添加一个具有itemscope
(但没有itemtype
)作为breadcrumbs
属性父级的div
,并使用itemref
将breadcrumb
属性添加到WebPage
项目.
There is an ugly solutions for this: add a div
with an itemscope
(but without itemtype
) as parent for the breadcrumbs
property, and use itemref
to add the breadcrumb
property to the WebPage
item.
<body itemscope="itemscope" itemtype="http://schema.org/WebPage" itemref="breadcrumbs">
<div itemprop="mainContentOfPage" itemscope="itemscope" itemtype="http://schema.org/WebPageElement">
<div itemscope>
<div itemprop="breadcrumb" itemscope="itemscope" itemtype="http://schema.org/BreadcrumbList" id="breadcrumbs">…</div>
</div>
</div>
</body>
我不建议这样做(但这是有效的微数据).您确实应该尝试更改标记结构,这样就不必像这样嵌套它了.
I don’t recommend this (but it’s valid Microdata). You should really try to change the markup structure so that you don’t have to nest it like that.
话虽如此,您可能想使用 mainEntity
/ mainContentOfPage
,因为mainContentOfPage
仅用于WebPageElement
个项目,因此它不是很有用.
Having said that, you might want to use mainEntity
/mainEntityOfPage
instead of mainContentOfPage
, because mainContentOfPage
is only for WebPageElement
items, which makes it not very useful.
这篇关于结构化数据(微数据)和嵌入式项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!