Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Microdata - itemref to another itemscope (Person works for Organization)

The website of an organization, say "Sun Industries", would like to add a list of employees. The address and contact information of the organization is already present at the webpage, but the list of employees would be somewhere else.

So we have

<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>

and later on in the HTML5 code we will have

<div id="employee-1" itemscope itemtype="http://schema.org/Person">
  <span itemprop="name">John Doe</span>,
  <span itemprop="jobTitle">Sales Manager</span>
</div>

How do we link the two objects "organization" and "employee-1" together?

I tried to add the following child to the "employee-1" object

<meta itemprop="worksFor" itemscope itemtype="http://schema.org/Organization" itemref="organization">

but that did not work (at least not in Google's Structured Data Testing Tool).

How can I use the microdata property itemref correctly in this case?

Just to be clear, I also tried the following:

  • Add itemprop="worksFor" to the "organization" object.
  • Add itemref="organization" to the "employee" object.

So

<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>

but that gave me a Warning: Page contains property "worksfor" which is not part of the schema. for the "organization" object.

like image 835
Meteor Avatar asked Jun 19 '13 08:06

Meteor


People also ask

What is the function of microdata in html5?

Microdata is part of the WHATWG HTML Standard and is used to nest metadata within existing content on web pages. Search engines and web crawlers can extract and process microdata from a web page and use it to provide a richer browsing experience for users.

What is microdata in html5 and how is it created?

Microdata lets you define your own customized elements and start embedding custom properties in your web pages. At a high level, microdata consists of a group of name-value pairs. The groups are called items, and each name-value pair is a property. Items and properties are represented by regular elements.

What is the purpose of microdata?

Microdata is a type of specification language that is embedded within HTML content to improve machine readability, annotate elements and analyze web pages. This type of markup language assigns labels to identify individual pieces of content, allowing search engines to highlight or emphasize more relevant information.

What is microdata markup?

Microdata is a specification to embed machine-readable data in HTML documents. Microdata consists of name-value pairs (known as items ) defined according to a vocabulary. A collection of commonly used markup vocabularies are provided by schema.org.


3 Answers

Well, actually your last code snippet looks fine. Maybe with Yandex Validator the output will be more clear

person   itemType = http://schema.org/Person   worksfor     organization       itemType = http://schema.org/Organization       name = Sun Industries   name = John Doe   jobtitle = Sales Manager 

Couple of other working examples.

<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> 

Gives the following:

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 

Or this

<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> 

That results in

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 is not very clear about using itemref but example helps

<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> 
like image 127
ajax Avatar answered Oct 13 '22 01:10

ajax


Your last example is correct.
(Google’s testing tool no longer gives the mentioned error. Back then they were probably not up to date with new additions to the Schema.org vocabulary.)

Specification

Links to the itemref specifications:

  • W3C’s Microdata (Note): itemref
  • WHATWG’s HTML (Living Standard): Microdata: itemref

tl;dr:

  1. You specify itemref on the element (with itemscope) to which you want to add properties.
  2. You specify id on the element (with itemprop) which you want to add.

Examples

A minimal example:

<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>

This is equivalent to:

<div itemscope itemtype="http://schema.org/Person">

  <div itemprop="worksFor" itemscope itemtype="http://schema.org/Organization">
  </div>

</div>

Other examples:

  • adding meta elements from the head
  • adding the property specified on the body element to elements that are children of that body
  • adding an Event to an Action
  • adding a name property from a child item to the parent item
  • add a property that is a child of an Offer item to the parent Product item instead of the Offer
  • adding breadcrumb to WebPage
  • adding the Hotel as a branchOf an Organization
  • adding several related products to a Product
  • adding the Product to an Offer
  • two examples of relating Event items: either via superEvent or via subEvent

To keep in mind

  • The itemref attribute can only be used for elements in the same document.

  • You can reference multiple elements from one itemref attribute (separate the ID tokens with space characters).

  • The referenced element may be a container for multiple properties.

  • You have to make sure that the referenced elements are not children of an element with itemscope, otherwise their properties will also be added to this item (but you can circumvent this by adding a dummy itemscope).

like image 40
unor Avatar answered Oct 12 '22 23:10

unor


There are 2 ways to links schema data together.

  1. itemid: Link 2 complete objects (ie Organisation & Person)
  2. itemref: Link 1 complete object to 1 incomplete object (ie Article & Comments)

1st one is easy. All you do is add the itemid property onto item you wish to link and add a link on other item:

<div itemid='#org' itemscope itemType='http://schema.org/Organization'>
    <!-- ..... -->
</div>

<article itemscope itemType='http://schema.org/Article'>
    <link itemprop='publisher' href='#org'>
</article>

Second one is not so easy. What if the comments for your blog post are somewhere far away. How do you connect them to your blog post? You can create an empty item with an id and then connect it to your blog post like so:

<div id="comments" itemscope>
    <span itemprop="commentCount">0</span>
</div>

<div id="words" itemscope>
    <span itemprop="wordCount">0</span>
</div>

We don't need to give comments an itemType. All we need is to add itemscope. This way we get no validation errors. Now we can link the comments back to blog post like so:

<div itemscope itemtype="http://schema.org/BlogPosting" itemref="comments words">
    <!-- .... -->
</div>

Tada! We even managed to import wordCount as well.

like image 20
Walter Avatar answered Oct 13 '22 00:10

Walter