【问题标题】:How to add QuantitativeValue to Product instead of Offer?如何将 QuantitativeValue 添加到 Product 而不是 Offer?
【发布时间】:2014-04-21 21:09:08
【问题描述】:

我的页面结构如下:

<div id="product" itemscope itemtype="http://schema.org/Product">
<h1 itemprop="name">Product name</h1>
<!-- ... -->
<table itemprop="offers" itemscope itemtype="http://schema.org/Offer" id="product_description">
<tr><th>Weight:</th><td itemprop="weight" itemscope itemtype="http://schema.org/QuantitativeValue">3.75g</td></tr>
<tr><th>Width:</th><td itemprop="width" itemscope itemtype="http://schema.org/QuantitativeValue">20mm</td></tr>
<tr><th>Height:</th><td itemprop="height" itemscope itemtype="http://schema.org/QuantitativeValue">20mm</td></tr>
<tr><th>Availability:</th><td><link itemprop="availability" href="http://schema.org/InStock"/>available</td></tr>
<!-- ... -->

我希望将weightwidthheight 附加到Product 范围而不是Offer

我怎样才能做到这一点?

【问题讨论】:

    标签: html product microdata schema.org


    【解决方案1】:

    您必须通过添加额外的包装“itemscope”来“屏蔽”产品 itemprop(s) 并通过使用产品上的引用将 itemprop 分配给产品; 'itemref' 一个 id(s) 列表和目标标签上的 id(s)。

    您还必须将 QuantitativeValue(s) 拆分为 unitCode 和 value。

    谷歌提供测试工具https://developers.google.com/structured-data/testing-tool/

    单元代码列表可以在这里找到http://wiki.goodrelations-vocabulary.org/Documentation/UN/CEFACT_Common_Codes

    <div id="product" itemscope itemtype="http://schema.org/Product" itemref="weight width height">
      <h1 itemprop="name">Product name</h1>
    
      <table itemprop="offers" itemscope itemtype="http://schema.org/Offer">
        <tr>
          <th>Weight:</th>
          <td itemscope>
            <span id="weight" itemprop="weight" itemscope itemtype="http://schema.org/QuantitativeValue">
              <span itemprop="value">3.75</span>
              <abbr itemprop="unitCode" title="grams" content="GRM" >g</abbr>
            </span>
          </td>
        </tr>
        <tr>
          <th>Width:</th>
          <td itemscope>
            <span id="width" itemprop="width" itemscope itemtype="http://schema.org/QuantitativeValue">
              <span itemprop="value">20</span>
              <abbr itemprop="unitCode" content='MMT' title='millimetres' >mm</abbr>
            </span>
    
          </td>
        </tr>
        <tr>
          <th>Height:</th>
          <td itemscope>
            <span id="height" itemprop="height" itemscope itemtype="http://schema.org/QuantitativeValue">
              <span itemprop="value">20</span>
              <abbr itemprop="unitCode" content='MMT' title='millimetres' >mm</abbr>
            </span>
          </td>
        </tr>
        <tr>
          <th>Availability:</th>
          <td><link itemprop="availability" href="http://schema.org/InStock"/>available</td>
        </tr>
         ...
      </table>
    </div>
    

    【讨论】:

      【解决方案2】:

      您可以使用itemref attributes 将这些属性添加到Product但是这仍然无效,因为它们仍然适用于Offer(但这些属性不是允许这种类型)。

      因此,您必须将它们移出Offer 的范围。

      有多种方法可以做到这一点。如果没有查看完整的 HTML,就无法确定哪个有效或最好。

      如果表格不包含任何其他内容,您可以使用:

      <table>
        <tr><th>Weight:</th><td itemprop="weight" itemscope itemtype="http://schema.org/QuantitativeValue">3.75g</td></tr>
        <tr><th>Width:</th><td itemprop="width" itemscope itemtype="http://schema.org/QuantitativeValue">20mm</td></tr>
        <tr><th>Height:</th><td itemprop="height" itemscope itemtype="http://schema.org/QuantitativeValue">20mm</td></tr>
        <tr itemprop="offers" itemscope itemtype="http://schema.org/Offer"><th>Availability:</th><td><link itemprop="availability" href="http://schema.org/InStock"/>available</td></tr>
      </table>
      

      如果您有更多应该属于Offer 的行,您可以使用tbody element 对这些行进行分组:

      <table>
        <tbody>
          <tr><th>Weight:</th><td itemprop="weight" itemscope itemtype="http://schema.org/QuantitativeValue">3.75g</td></tr>
          <tr><th>Width:</th><td itemprop="width" itemscope itemtype="http://schema.org/QuantitativeValue">20mm</td></tr>
          <tr><th>Height:</th><td itemprop="height" itemscope itemtype="http://schema.org/QuantitativeValue">20mm</td></tr>
        </tbody>
        <tbody itemprop="offers" itemscope itemtype="http://schema.org/Offer">
          <tr><th>Availability:</th><td><link itemprop="availability" href="http://schema.org/InStock"/>available</td></tr>
        </tbody>
      </table>
      

      如果行是混合的(例如,前 3 行用于Product,然后 1 用于Offer,然后一些用于Product),您将不得不使用itemref 并省略嵌套:

      <div itemscope itemtype="http://schema.org/Product" itemref="product-weight product-width product-height">
        <h1 itemprop="name">Product name</h1>
      
        <div itemprop="offers" itemscope itemtype="http://schema.org/Offer" itemref="offer-availability">
        </div>
      
      </div>
      
      <!-- not nested under any itemscope -->
      <table>
        <tr><th>Weight:</th><td id="product-weight" itemprop="weight" itemscope itemtype="http://schema.org/QuantitativeValue">3.75g</td></tr>
        <tr><th>Width:</th><td id="product-width" itemprop="width" itemscope itemtype="http://schema.org/QuantitativeValue">20mm</td></tr>
        <tr><th>Height:</th><td id="product-height" itemprop="height" itemscope itemtype="http://schema.org/QuantitativeValue">20mm</td></tr>
        <tr><th>Availability:</th><td><link id="offer-availability" itemprop="availability" href="http://schema.org/InStock"/>available</td></tr>
      </table>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-20
        • 2013-01-13
        • 1970-01-01
        • 1970-01-01
        • 2012-08-03
        相关资源
        最近更新 更多