如何从标题中的元标记正确引用微数据项? [英] How to correctly reference Microdata item from meta tag in header?

查看:138
本文介绍了如何从标题中的元标记正确引用微数据项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

https://google.com/webmasters/markup-tester/ ):网站不是有效类型。

when validating with Google ( https://google.com/webmasters/markup-tester/ ): "WebSite is not a valid type."

使用 https://validator.nu/ 告诉我元元素缺少必需的属性内容。

Using https://validator.nu/ gives me "Element meta is missing required attribute content".

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

Any suggestions on how to fix this?

推荐答案

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

You have to specify the itemref on the itemscope to which you want to add properties (i.e., the html element in your case). And the element with the corresponding id would have to get the itemprop.

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

However, in your case you don’t need the meta element, and you don’t need to use 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>

但是假设你使用另一个 itemscope (例如,对于正文上的 WebPage 项目,在这种情况下你需要使用 itemref

But let’s say you use another itemscope (e.g., for a WebPage item) on the body, in which case you’d need to use 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>

现在创建者属性将应用于两个项目( WebSite 感谢 itemref WebPage ,因为这是个孩子。)

Now the creator property will be applied to both items (WebSite thanks to itemref, and WebPage because it’s a child).

这篇关于如何从标题中的元标记正确引用微数据项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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