【问题标题】:How to correctly reference Microdata item from meta tag in header?如何从标题中的元标记正确引用微数据项?
【发布时间】:2016-03-18 11:18:20
【问题描述】:
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/WebSite">
<head>
  <meta itemprop="creator" itemscope itemref="mdFoo">
</head>
<body>

 <div id="mdFoo" itemscope itemtype="http://schema.org/LocalBusiness">
        <meta itemprop="name" content="Foo comp">
        <meta itemprop="telephone" content="0">
        <meta itemprop="legalName" content="Foo comp Ltd">
        <meta itemprop="url" content="http://www.foo.com">
        <meta itemprop="email" content="info@foo.com">
        <div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
            <meta itemprop="streetAddress" content="mystreet">
            <meta itemprop="postalCode" content="1233">
            <meta itemprop="addressLocality" content="London">
            <meta itemprop="addressCountry" content="UK">
        </div>
    </div>

</body>
</html>

当使用 Google (https://google.com/webmasters/markup-tester/) 进行验证时:“WebSite 不是有效类型。”

使用 https://validator.nu/ 会给我“元素元缺少必需的属性内容”。

关于如何解决此问题的任何建议?

【问题讨论】:

标签: html schema.org microdata


【解决方案1】:

您必须在要添加属性的itemscope 上指定itemref(即,在您的情况下为html 元素)。而具有相应id 的元素必须得到itemprop

但是,在您的情况下,您不需要meta 元素,也不需要使用itemref

<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/WebSite">
<head>
  <title>…</title>
</head>
<body>

  <div itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness">
  </div>

</body>
</html>

但是假设您在body 上使用另一个itemscope(例如,用于WebPage 项目),在这种情况下您需要使用itemref

<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/WebSite" itemref="mdFoo">
<head>
  <title>…</title>
</head>
<body itemscope itemtype="http://schema.org/WebPage">

  <div itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness" id="mdFoo">
  </div>

</body>
</html>

现在creator 属性将应用于这两个项目(WebSite 感谢itemrefWebPage 因为它是一个孩子)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    相关资源
    最近更新 更多