14

您好,我有一个包含评论 ( http://schema.org/Review ) 的页面 ( http://schema.org/WebPage )

问题是:

  • 如何处理重复的内容?
  • 是否正确制作元素属于两个或多个范围?
  • 如何做到这一点,重复文本两次?
  • 或者我应该避免多次引用?

例子:

<html itemscope itemtype="http://schema.org/WebPage">
    <meta name="description" content="_________" itemprop="description">
    ...
    <div itemscope itemtype="http://schema.org/Review">
        <div itemprop="description">_________</div>
    </div>
    ...
</html>

描述属于评论和网页,所以......在这种情况下我应该写什么?

(注意:在前面的例子中,字符串“ _ _ ”是同一个文本段落,重复了两次)


编辑:

这可以是一个解决方案吗?(html5规范没有讨论这个,但是定义了itemref属性)

<html itemscope itemtype="http://schema.org/WebPage" id="WEBPAGE">
    ...
    <div itemscope itemtype="http://schema.org/Review" id="REVIEW">
        <div itemprop="description" itemref="WEBPAGE REVIEW">_________</div>
    </div>
    ...
</html>

随意改进问题!

4

1 回答 1

23

快速解答

  • 如何处理重复的内容?
    • 使用属性 itemref
  • 是否正确制作元素属于两个或多个范围?
    • 是的,这就是您使用 itemref 的目的
  • 如何做到这一点,重复文本两次?
    • 不,你只需要引用元素
  • 或者我应该避免多次引用?
    • 我看不出你不想使用多个参考的任何理由

一些例子

通过包装包含

当您使用 itemref 属性时,您会将所引用元素中包含的所有属性包含在不同的范围内。

<body itemscope itemtype="http://schema.org/WebPage" itemref="wrapper">
    ...
    <div itemscope itemtype="http://schema.org/Review">
        ...
        <div id="wrapper">
            <div itemprop="description">_________</div>

            <div itemprop="some-other-property">_________</div>
        </div>
        ...
    </div>
    ...
</body>

通过包装包含 - 一个不同的例子

假设您的产品在范围之外提供了一些不同的优惠。

<div itemscope itemtype="http://schema.org/Product" itemref="wrapper">
    ...
</div>

<div id="wrapper">
    <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
        ...
    </div>

    <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
        ...
    </div>

    <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
        ...
    </div>
</div>

包含特定属性

您可能只希望在范围之外包含一个特定属性,为此我们可以简单地在指定 itemprop 的目标元素上直接设置 id。

<body itemscope itemtype="http://schema.org/WebPage" itemref="target">
    ...
    <div itemscope itemtype="http://schema.org/Review">
        <div id="target" itemprop="description">_________</div>
    </div>
    ...
</body>

多个参考

也许包装器不适用,那么您可以使用多个引用。您只需用空格将它们分开。

<body itemscope itemtype="http://schema.org/WebPage" itemref="desc name">
    ...
    <div itemscope itemtype="http://schema.org/Review">
        <div id="desc" itemprop="description">_________</div>

        <div id="name" itemprop="name">_________</div>
    </div>
    ...
</body>

来源

另请参阅thees页面以获取其他一些解释和示例:
http ://www.w3.org/TR/2011/WD-microdata-20110405/
http://www.whatwg.org/specs/web-apps/current-work /multipage/microdata.html

于 2012-05-07T05:47:38.047 回答