链接微数据中的独立元素
Linking independent elements in Microdata
我正在创建一个关于作者的网站。他是主题。在这个网站上也展示了他的著作。
不幸的是,我找不到 link 这些书到主要人物元素的解决方案。我尝试了 itemref
,但是当 linking 到这样的 'independent' 元素时它不起作用,它没有 itemprop
值(说 Google 测试工具) .以下两个 "book" 案例均无效。
<div id="author" itemscope="" itemtype="http://schema.org/Person">
<span itemprop="name">Marvin</span>
</div>
<div itemscope="" itemtype="http://schema.org/Book">
<span itemprop="name">Nice Book</span>
<meta itemprop="author" itemref="author" />
</div>
<div itemscope="" itemtype="http://schema.org/Book">
<span itemprop="name">Best Book</span>
<meta itemprop="author" itemscope="" itemtype="http://schema.org/Person" itemref="author" />
</div>
还有其他想法吗?
您可以使用 link
标记来实现此目的,请查看以下代码段:
<div itemid="#author-marvin" itemscope="" itemtype="http://schema.org/Person">
<span itemprop="name">Marvin</span>
</div>
<div itemscope="" itemtype="http://schema.org/Book">
<span itemprop="name">Nice Book</span>
<link itemprop="author" href="#author-marvin">
</div>
<div itemscope="" itemtype="http://schema.org/Book">
<span itemprop="name">Best Book</span>
<link itemprop="author" href="#author-marvin">
</div>
作者摘要的 itemid
应与整个页面标记中书籍摘要中 link
的 href
匹配。
更多示例here
你有三个选择。
itemid
如。您给 Person
一个 URI(带有 itemid
属性)并在每个 Book
中用 author
属性.
引用这个 URI
<div itemscope itemtype="http://schema.org/Person" itemid="#person-1">
</div>
<div itemscope itemtype="http://schema.org/Book">
<link itemprop="author" href="#person-1" />
</div>
<div itemscope itemtype="http://schema.org/Book">
<link itemprop="author" href="#person-1" />
</div>
(这个 URI 可以被其他人使用,他们也想谈论这个人,或者想要识别那个人。所以 [your-domain]/[your-path]#person-1
是一个代表实际人的 URI,而不仅仅是一个关于那个人的页面。如果已经有那个人的这样一个 URI,你可能想重用它而不是创建你自己的。)
问题:消费者支持可能不是最好的(但Google的测试工具似乎可以识别)。
itemref
您必须将 itemprop="author"
添加到 Person
项,并使用 itemref
属性从每个 Book
引用其 id
。您不必为此添加 meta
元素,只需在带有 itemscope
.
的元素上添加即可
<div itemprop="author" itemscope itemtype="http://schema.org/Person" id="author">
</div>
<div itemscope itemtype="http://schema.org/Book" itemref="author">
</div>
<div itemscope itemtype="http://schema.org/Book" itemref="author">
</div>
问题: Person
项不能有父项 itemscope
(因为它的 author
属性 会被添加到它)。因此,这意味着,例如,您不能使用 mainEntity
属性 来表示 Person
是 WebPage
.
的主要主题
itemprop-reverse
如果可以将 Book
项嵌套在 Person
项中,则可以使用 itemprop-reverse
属性,它允许您在另一个方向使用属性:
<div itemscope itemtype="http://schema.org/Person">
<div itemprop-reverse="author" itemscope itemtype="http://schema.org/Book">
</div>
<div itemprop-reverse="author" itemscope itemtype="http://schema.org/Book">
</div>
</div>
(如果你不能嵌套,你仍然可以将它与 URI 值一起使用,但在这种情况下使用 itemid
可能是更好的选择。)
问题:此属性不是微数据规范的一部分。是 defined in W3C’s Microdata to RDF Note。所以消费者支持可能不是很好。 Google的测试工具好像不能识别
我正在创建一个关于作者的网站。他是主题。在这个网站上也展示了他的著作。
不幸的是,我找不到 link 这些书到主要人物元素的解决方案。我尝试了 itemref
,但是当 linking 到这样的 'independent' 元素时它不起作用,它没有 itemprop
值(说 Google 测试工具) .以下两个 "book" 案例均无效。
<div id="author" itemscope="" itemtype="http://schema.org/Person">
<span itemprop="name">Marvin</span>
</div>
<div itemscope="" itemtype="http://schema.org/Book">
<span itemprop="name">Nice Book</span>
<meta itemprop="author" itemref="author" />
</div>
<div itemscope="" itemtype="http://schema.org/Book">
<span itemprop="name">Best Book</span>
<meta itemprop="author" itemscope="" itemtype="http://schema.org/Person" itemref="author" />
</div>
还有其他想法吗?
您可以使用 link
标记来实现此目的,请查看以下代码段:
<div itemid="#author-marvin" itemscope="" itemtype="http://schema.org/Person">
<span itemprop="name">Marvin</span>
</div>
<div itemscope="" itemtype="http://schema.org/Book">
<span itemprop="name">Nice Book</span>
<link itemprop="author" href="#author-marvin">
</div>
<div itemscope="" itemtype="http://schema.org/Book">
<span itemprop="name">Best Book</span>
<link itemprop="author" href="#author-marvin">
</div>
作者摘要的 itemid
应与整个页面标记中书籍摘要中 link
的 href
匹配。
更多示例here
你有三个选择。
itemid
如Person
一个 URI(带有 itemid
属性)并在每个 Book
中用 author
属性.
<div itemscope itemtype="http://schema.org/Person" itemid="#person-1">
</div>
<div itemscope itemtype="http://schema.org/Book">
<link itemprop="author" href="#person-1" />
</div>
<div itemscope itemtype="http://schema.org/Book">
<link itemprop="author" href="#person-1" />
</div>
(这个 URI 可以被其他人使用,他们也想谈论这个人,或者想要识别那个人。所以 [your-domain]/[your-path]#person-1
是一个代表实际人的 URI,而不仅仅是一个关于那个人的页面。如果已经有那个人的这样一个 URI,你可能想重用它而不是创建你自己的。)
问题:消费者支持可能不是最好的(但Google的测试工具似乎可以识别)。
itemref
您必须将 itemprop="author"
添加到 Person
项,并使用 itemref
属性从每个 Book
引用其 id
。您不必为此添加 meta
元素,只需在带有 itemscope
.
<div itemprop="author" itemscope itemtype="http://schema.org/Person" id="author">
</div>
<div itemscope itemtype="http://schema.org/Book" itemref="author">
</div>
<div itemscope itemtype="http://schema.org/Book" itemref="author">
</div>
问题: Person
项不能有父项 itemscope
(因为它的 author
属性 会被添加到它)。因此,这意味着,例如,您不能使用 mainEntity
属性 来表示 Person
是 WebPage
.
itemprop-reverse
如果可以将 Book
项嵌套在 Person
项中,则可以使用 itemprop-reverse
属性,它允许您在另一个方向使用属性:
<div itemscope itemtype="http://schema.org/Person">
<div itemprop-reverse="author" itemscope itemtype="http://schema.org/Book">
</div>
<div itemprop-reverse="author" itemscope itemtype="http://schema.org/Book">
</div>
</div>
(如果你不能嵌套,你仍然可以将它与 URI 值一起使用,但在这种情况下使用 itemid
可能是更好的选择。)
问题:此属性不是微数据规范的一部分。是 defined in W3C’s Microdata to RDF Note。所以消费者支持可能不是很好。 Google的测试工具好像不能识别