How do I relate items in schema.org?

非 Y 不嫁゛ 提交于 2019-11-29 01:40:33

//Update : Schema.org expanded their specifications of perso schema

obviously the Person is related to the Company, so what you can do is to make a relation between person and organisation wit "person´s" itemprop "affiliation" so what i did is wrapping the paragraphs with itemscope itemtype="Person" and expanded the Schema Person by adding itemprop"affiliation" and itemscope itemtype="Organization" so now theres a semantic relation, the person is affiliated with the organization. I also added meta tag with itemprop="name" because it´s needed to fulfill "Person" specifications

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>New Job for John Doe</title>
</head>
<body>
<div itemscope itemtype="http://schema.org/Person">
    <h1>New Job for John Doe</h1>
<meta itemprop="name" content="John Doe" />
    <p>This week John Doe accepted an offer to become a <span itemprop="jobTitle">Software Engineer</span> at <span itemprop="worksFor">MITRE</span>.  John graduated from <span itemprop="alumniOf">MIT</span> in 2005 with a BS in Computer Science.  He previously worked at a small company near Boston.  Blah, blah, blah.</p>
    <p itemprop="affiliation" itemscope itemtype="http://schema.org/Organization">The MITRE Corporation is a not-for-profit organization chartered to work in the public interest.  The MITRE Corporation has two principal locations: <span itemprop="location">Bedford, Massachusetts</span>, and <span itemprop="location">McLean, Virginia</span>.  Blah, blah, blah.</p>
</div> <!-- closing Schema "Person" -->
</body>
</html>

You can put this into google rich snippet testing tool and i guess the Output is what you where looking for

Item 
type:   http://schema.org/person
property:   
name:   John Doe
jobtitle:   Software Engineer
worksfor:   MITRE
alumniof:   MIT
affiliation: Item 1


Item 1
type:   http://schema.org/organization
property:   
location:   Bedford, Massachusetts
location:   McLean, Virginia
james.garriss

My first attempt to answer my own question was to use the itemref attribute, like so:

<p itemscope itemtype="http://schema.org/Person">
    This week John Doe accepted an offer to become a
    <span itemprop="jobTitle">Software Engineer</span>
    at <span itemprop="worksFor" itemref="TheMitreCorporation">MITRE</span>.
    John graduated from <span itemprop="alumniOf">MIT</span>
    in 2005 with a BS in Computer Science.
    He previously worked at a small company near Boston.  Blah, blah, blah.
</p>

<p itemscope itemtype="http://schema.org/Corporation" id="TheMitreCorporation">
    The MITRE Corporation is a not-for-profit organization chartered to work in the public interest.
    The MITRE Corporation has two principal locations:
    <span itemprop="location" itemscope itemtype="http://schema.org/Place">
        <span itemprop="name">Bedford, Massachusetts</span>
    </span>, and
    <span itemprop="location" itemscope itemtype="http://schema.org/Place">
        <span itemprop="name">McLean, Virginia</span>
    </span>. Blah, blah, blah.
</p>

But some of the commenters rightly pointed out this was not the right use of this attribute.

So here's my second attempt: Use the itemid attribute instead. Both instances of the company name are given an itemscope and itemtype attribute, and they are both set to the same itemid value, which is a URL.

The spec says: "The itemid attribute, if specified, must have a value that is a valid URL potentially surrounded by spaces...The global identifier of an item is the value of its element's itemid attribute, if it has one, resolved relative to the element on which the attribute is specified...The itemid attribute must not be specified on elements that do not have both an itemscope attribute and an itemtype attribute specified."

<p itemscope itemtype="http://schema.org/Person">This week John Doe accepted an offer to become a <span itemprop="jobTitle">Software Engineer</span> at <span itemprop="worksFor" itemscope itemtype="http://schema.org/Corporation" itemid="http://www.mitre.org">MITRE</span>.  John graduated from <span itemprop="alumniOf">MIT</span> in 2005 with a BS in Computer Science.  He previously worked at a small company near Boston.  Blah, blah, blah.</p>
<p itemscope itemtype="http://schema.org/Corporation" itemid="http://www.mitre.org">The MITRE Corporation is a not-for-profit organization chartered to work in the public interest.  The MITRE Corporation has two principal locations: <span itemprop="location" itemscope itemtype="http://schema.org/Place"><span itemprop="name">Bedford, Massachusetts</span></span>, and <span itemprop="location" itemscope itemtype="http://schema.org/Place"><span itemprop="name">McLean, Virginia</span></span>.  Blah, blah, blah.</p>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!