如何将itemscope拆分为多个HTML元素? [英] How to split itemscope over multiple HTML elements?

查看:82
本文介绍了如何将itemscope拆分为多个HTML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML:

<body itemscope itemtype="http://schema.org/WebPage">
  <header itemscope itemtype="http://schema.org/WPHeader">
    <nav itemscope itemtype="http://schema.org/SiteNavigationElement">
    </nav>
    ...
    <div itemscope itemtype="http://schema.org/Organization" itemref="objectDetails">
      <span itemprop="name">Org name</span><br>
      <span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
        ...
      </span>
    </div>
  </header>
  <ul itemprop="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">
    <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">..</li>
    ...
  </ul>
  <div id="objectDetails">
    <div itemprop="description">...</div>
    <div itemprop="foundingDate">...</div>
    ...
  </div>
</body>

此网页显示有关一个特定组织的信息.有关组织的某些信息应显示在页面标题中,其他信息应显示在页面中心.借助 itemref 属性,我可以拆分有关组织的信息,并将其放在两个单独的div上.

This web page displays information about one particular organization. Some information about organization should be displayed in a page header, other - in the center of a page. With the help of itemref attribute I can split information about organization and put it on two separate divs.

如果我使用google结构化数据测试工具测试以上HTML,它会正确提取有关组织的信息,但会显示两个div的属性,但会在WebPage对象上显示验证错误:

If I test the above HTML with google structured data testing tool - it extracts info about organization correctly - properties from both divs are shown, but it shows validation error on a WebPage object:

对于类型为 WebPage 的对象,Google无法识别属性 foundingDate .

The property foundingDate is not recognized by Google for an object of type WebPage.

告诉Google,objectDetails div内部的属性不属于外部itemscope(WebPage)的正确方法是什么?如果我将 itemscope itemtype ="http://schema.org/Organization" 添加到objectDetails div中,则Google会在我的网页上看到两个独立的组织.

What is the correct way to tell Google that properties that are inside objectDetails div doesn't belong to the outer itemscope (WebPage)? If I add itemscope itemtype="http://schema.org/Organization" to objectDetails div - then Google sees two separate organizations on my WebPage.

推荐答案

这是不可能的.

可能的解决方案":

  • 请勿在容器"上使用任何物品,例如 html body .在不涵盖全部内容的元素上使用它,并在需要时使用 itemref .

  • Don’t use an item on a "container" like html or body. Use it on an element that doesn’t span the whole content, and use itemref if needed.

使用多个项目,并在 itemid 中为它们指定相同的URI.但是,尚不清楚是否/何时/如何/Schema.org如何支持 itemid ,以及来自消费者可能是坏人.

Use multiple items and specify the same URI in itemid for them. However, it’s not clear if/when/how Schema.org supports itemid, and support from consumers is probably bad.

(使用使用RDFa代替微数据自然可以做到这一点.)

(Using RDFa instead of Microdata would allow this naturally.)

向包含不想添加到原始父项的所有属性的元素中添加未类型化的项(通过添加没有 itemtype itemscope ).示例: 1 2 3 .

Add an untyped item (by adding an itemscope without itemtype) to the element containing all properties you don’t want to add to the original parent item. Examples: 1, 2, 3.

这篇关于如何将itemscope拆分为多个HTML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆