我正在尝试使用schema.org微数据在产品页面上指明多个相关产品。但是儿童产品是孤儿,因为它们不包含在父div中。我尝试使用itemref
,但我必须使用它不正确,否则一定是错误的解决方案。
另外,我无法轻松创建包装器div或使用body
元素创建父级。我理想的解决方案是将页面结构保持原样,并以某种方式将“子产品”div链接到父级。我认为itemref
会这样做,但似乎没有效果。
以下是HTML示例。
<div id="main-product" itemscope itemtype="http://schema.org/Product">
<div class="product-name">
<h1 itemprop="name">Main Product</h1>
</div>
</div>
<!-- END main-product div -->
<!-- START related-products div -->
<div class="related-products">
<ol class="products-list" id="related-products-list">
<li class="item">
<div class="product" itemprop="isRelatedTo" itemscope itemtype="http://schema.org/Product" itemref="main-product">
<p class="product-name"><a itemprop="url" href="/some_product1.php"><span itemprop="name">Some Product 1</span></a></p>
</div>
</li>
<li class="item">
<div class="product" itemprop="isRelatedTo" itemscope itemtype="http://schema.org/Product" itemref="main-product">
<p class="product-name"><a itemprop="url" href="/some_product2.php"><span itemprop="name">Some Product 2</span></a></p>
</div>
</li>
</ol>
</div>
上述HTML已经过简化,但结构与我网站上的内容类似,并且在提交给验证者时会出现类似的错误。
E.g。 http://webmaster.yandex.com/microtest.xml
给出:
microdata
ERROR: unable to determine affiliation of these fields. There are two possible reasons: this fields are incorrectly placed or an orphan itemprop attribute is indicated
itemType = orphans
isrelatedto
product
itemType = http://schema.org/Product
url
href = /some_product1.php
text = Some Product 1
name = Some Product 1
isrelatedto
product
itemType = http://schema.org/Product
url
href = /some_product2.php
text = Some Product 2
name = Some Product 2
product
itemType = http://schema.org/Product
name = Main Product
Google validator似乎没有显示任何错误,但子产品与母产品无关。
答案 0 :(得分:1)
You don’t use itemref
correctly.
您必须在主要产品上指定itemref
而不是相关产品:
<div itemref="product-1 product-2" itemscope itemtype="http://schema.org/Product">
<span itemprop="name">Product</span>
</div>
<div id="product-1" itemprop="isRelatedTo" itemscope itemtype="http://schema.org/Product">
<span itemprop="name">Product 1</span>
</div>
<div id="product-2" itemprop="isRelatedTo" itemscope itemtype="http://schema.org/Product">
<span itemprop="name">Product 2</span>
</div>