一个组织的网站,比如“Sun Industries”,想要添加一份员工名单。组织的地址和联系信息已经出现在网页上,但员工名单将出现在其他地方。
所以我们有
<div id="organization" itemscope itemtype="http://schema.org/Organization">
<span itemprop="name">Sun Industries</span>,
<span itemprop="location" itemscope itemtype="http://schema.org/Place">
<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<span itemprop="streetAddress">Technologies Street 42</span>,
<span itemprop="addressLocality">Venustown</span>
<span itemprop="postalCode">98765</span>
</span>
</span>
</div>
以及稍后的HTML5代码中我们将
<div id="employee-1" itemscope itemtype="http://schema.org/Person">
<span itemprop="name">John Doe</span>,
<span itemprop="jobTitle">Sales Manager</span>
</div>
我尝试将以下子项添加到“employee-1”对象
<meta itemprop="worksFor" itemscope itemtype="http://schema.org/Organization" itemref="organization">
但这不起作用(至少在谷歌的结构化数据测试工具中没有)。
itemref
?为了清楚起见,我也尝试了以下内容:
itemprop="worksFor"
添加到“组织”对象。itemref="organization"
添加到“employee”对象。所以
<div id="organization" itemprop="worksFor" itemscope itemtype="http://schema.org/Organization">
<span itemprop="name">Sun Industries</span>,
...
</div>
...
<div id="employee-1" itemscope itemtype="http://schema.org/Person" itemref="organization">
<span itemprop="name">John Doe</span>,
<span itemprop="jobTitle">Sales Manager</span>
</div>
但是这为“组织”对象提供了Warning: Page contains property "worksfor" which is not part of the schema.
。
答案 0 :(得分:27)
嗯,实际上你的最后一段代码看起来不错。 也许使用Yandex Validator输出会更清晰
person
itemType = http://schema.org/Person
worksfor
organization
itemType = http://schema.org/Organization
name = Sun Industries
name = John Doe
jobtitle = Sales Manager
其他一些工作实例。
<body>
<div id="organization" itemscope itemtype="http://schema.org/Organization" itemref="employee-1">
<span itemprop="name">Sun Industries</span>,
<span itemprop="location" itemscope itemtype="http://schema.org/Place">
<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<span itemprop="streetAddress">Technologies Street 42</span>,
<span itemprop="addressLocality">Venustown</span>
<span itemprop="postalCode">98765</span>
</span>
</span>
</div>
<div id="employee-1" itemprop="employee" itemscope itemtype="http://schema.org/Person">
<span itemprop="name">John Doe</span>,
<span itemprop="jobTitle">Sales Manager</span>
</div>
</body>
给出以下内容:
organization
itemType = http://schema.org/Organization
employee
person
itemType = http://schema.org/Person
name = John Doe
jobtitle = Sales Manager
name = Sun Industries
location
place
itemType = http://schema.org/Place
address
postaladdress
itemType = http://schema.org/PostalAddress
streetaddress = Technologies Street 42
addresslocality = Venustown
postalcode = 98765
或者这个
<body>
<div id="employee-1" itemscope itemtype="http://schema.org/Person">
<span itemprop="name">John Doe</span>,
<span itemprop="jobTitle">Sales Manager</span>
<meta itemprop="worksFor" itemscope itemtype="http://schema.org/Organization" itemref="organization">
</div>
<div id="organization">
<span itemprop="name">Sun Industries</span>,
<span itemprop="location" itemscope itemtype="http://schema.org/Place">
<span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<span itemprop="streetAddress">Technologies Street 42</span>,
<span itemprop="addressLocality">Venustown</span>
<span itemprop="postalCode">98765</span>
</span>
</span>
</div>
</body>
导致
person
itemType = http://schema.org/Person
name = John Doe
jobtitle = Sales Manager
worksfor
organization
itemType = http://schema.org/Organization
name = Sun Industries
location
place
itemType = http://schema.org/Place
address
postaladdress
itemType = http://schema.org/PostalAddress
streetaddress = Technologies Street 42
addresslocality = Venustown
postalcode = 98765
Spec不是很清楚使用 itemref ,但示例帮助
<div itemscope id="amanda" itemref="a b"></div>
<p id="a">Name: <span itemprop="name">Amanda</span></p>
<div id="b" itemprop="band" itemscope itemref="c"></div>
<div id="c">
<p>Band: <span itemprop="name">Jazz Band</span></p>
<p>Size: <span itemprop="size">12</span> players</p>
</div>
答案 1 :(得分:6)
你的最后一个例子是正确的 (Google的测试工具不再提供上述错误。当时他们可能不会更新Schema.org词汇表的新增内容。)
指向itemref
规范的链接:
tl; dr :
itemref
)上指定itemscope
。id
)上指定itemprop
。一个最小的例子:
<div itemprop="worksFor" itemscope itemtype="http://schema.org/Organization" id="org">
<!-- this property (worksFor) gets added to the Person item below -->
</div>
<div itemscope itemtype="http://schema.org/Person" itemref="org">
<!-- looks for the element with the ID "org" -->
</div>
这相当于:
<div itemscope itemtype="http://schema.org/Person">
<div itemprop="worksFor" itemscope itemtype="http://schema.org/Organization">
</div>
</div>
其他例子:
meta
elements from the head
body
element to elements that are children of that body
Event
to an Action
name
property from a child item to the parent item Offer
item to the parent Product
item instead of the Offer
breadcrumb
to WebPage
Hotel
as a branchOf
an Organization
Product
Product
to an Offer
Event
items: either via superEvent
or via subEvent
itemref
属性只能用于同一文档中的元素。
您可以从一个itemref
属性引用多个元素(使用空格字符分隔ID标记)。
引用的元素可以是多个属性的容器。
您必须确保引用的元素不是itemscope
元素的子元素,否则它们的属性也会添加到此项目中(但您可以规避这是adding a dummy itemscope
)。
答案 2 :(得分:0)
有两种方法可以将架构数据链接在一起。
第一个很容易。您所要做的就是将itemid
属性添加到您想要关联的项目上,并在其他项目上添加link
:
<div itemid='#org' itemscope itemType='http://schema.org/Organization'>
<!-- ..... -->
</div>
<article itemscope itemType='http://schema.org/Article'>
<link itemprop='publisher' href='#org'>
</article>
第二个并不容易。如果您的博客帖子的评论在某个地方很远,该怎么办?你如何将它们连接到你的博客文章?您可以使用ID创建一个空项目,然后将其连接到您的博客帖子,如下所示:
<div id="comments" itemscope>
<span itemprop="commentCount">0</span>
</div>
<div id="words" itemscope>
<span itemprop="wordCount">0</span>
</div>
我们不需要发表评论itemType
。我们所需要的只是添加itemscope
。这样我们就不会出现验证错误。现在我们可以将评论链接回博客帖子,如下所示:
<div itemscope itemtype="http://schema.org/BlogPosting" itemref="comments words">
<!-- .... -->
</div>
多田!我们甚至设法导入wordCount
。