当不包含在子元素中时,将 `isRelated` schema.org 链接到父 `Product` [英] Link `isRelated` schema.org to parent `Product` when not contained in child element

查看:36
本文介绍了当不包含在子元素中时,将 `isRelated` schema.org 链接到父 `Product`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 schema.org 微数据在产品页面上指示多个相关产品.但是子产品是孤立的,因为它们不包含在父 div 中.我尝试使用 itemref 但我一定是使用不正确或者它一定是错误的解决方案.

此外,我无法轻松创建包装 div 或使用 body 元素来创建父元素.我的理想解决方案是将页面结构保持原样,并以某种方式将子产品"div 链接到父级.我以为 itemref 会这样做,但它似乎不起作用.

这是示例 HTML.

<div class="product-name"><h1 itemprop="name">主要产品</h1>

<!-- END main-product div --><!-- 开始相关产品 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></</p>

<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></</p>

</ol>

上面的 HTML 已经过简化,但在结构上与我网站上的类似,并且在提交给验证器时会出现类似的错误.

例如http://webmaster.yandex.com/microtest.xml

给出:

微数据错误:无法确定这些字段的从属关系.有两个可能的原因:这个字段放置不正确或指示了一个孤立的 itemprop 属性itemType = 孤儿与产品itemType = http://schema.org/Product网址href =/some_product1.php文字 = 一些产品 1名称 = 某些产品 1与产品itemType = http://schema.org/Product网址href =/some_product2.php文字 = 一些产品 2名称 = 某些产品 2产品itemType = http://schema.org/Product名称 = 主要产品

Google 验证器似乎没有显示任何错误,但子产品与父产品无关.

解决方案

你不用itemref正确.

您必须在主要产品而不是相关产品上指定itemref:

<span itemprop="name">产品</span>

<div id="product-1" itemprop="isRelatedTo" itemscope itemtype="http://schema.org/Product"><span itemprop="name">产品 1</span>

<div id="product-2" itemprop="isRelatedTo" itemscope itemtype="http://schema.org/Product"><span itemprop="name">产品 2</span>

I'm trying to indicate multiple related products on a product page using schema.org microdata. But the child products are orphaned because they are not contained in the parent div. I tried using itemref but I must be using it incorrectly or it must be the wrong solution.

ALSO, I cannot easily create a wrapper div or use the body element to create the parent. My ideal solution would be one that leaves the page structure as-is, and somehow links the "child product" divs to the parent. I thought itemref would do that, but it doesn't appear to be working.

Here is example 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>

The above HTML is simplified, but similar in structure to what's on my site and gives similar errors when submitted to validators.

E.g. http://webmaster.yandex.com/microtest.xml

Gives:

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

The Google validator does not seem to show any errors, but the child products are not related to the parent product.

解决方案

You don’t use itemref correctly.

You’d have to specify itemref on the main product instead of the related products:

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

这篇关于当不包含在子元素中时,将 `isRelated` schema.org 链接到父 `Product`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆