本文介绍了我如何有一个itemprop嵌套在一个itemscope中实际上应用于不同的itemscope?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b $

以下是我的代码摘要(我已经删除了页面上的类和其他无关元素,以专注于重要的内容):

 <! -  CODE I HAD  - > 

< div itemscope itemtype =http://schema.org/Product>
< div itemprop =aggregateRatingitemscope itemtype =http://schema.org/AggregateRating>
< span itemprop =ratingValue> 79< / span>
< h1 itemprop =name> Someproductsoandso< / h1>
< span itemprop =reviewCount> 830< / span>
< / div>
< / div>

<! - 我现在拥有的代码 - >

< div itemscope itemtype =http://schema.org/Productitemref =productMicrodata>
< div itemprop =aggregateRatingitemscope itemtype =http://schema.org/AggregateRating>
< span itemprop =ratingValue> 79< / span>
< h1 itemprop =nameid =productMicrodata> Someproductsoandso< / h1>
< span itemprop =reviewCount> 830< / span>
< / div>
< / div>

基本上,我有一个带有子聚合评分的产品项目范围。在aggregateRating范围内,我有一些东西,比如我想要附加的ratingValue和reviewCount,但是还有一个名称值,我想要附加到Product上(不是aggregateRating,它也可以有一个name 价值)。

在我使用的第一部分代码中,google表示我的产品缺少名称,因为名称正在应用于aggregateRating;第二名的名字现在被应用于aggregateRating和Product。这不是最糟糕的事情,但我希望它只是附加在aggregateRating上;你知道如何解决这个问题,而不会浪费当前的标记组织吗? 解决方案

假设你的意思是你想要它只附加到产品,根据你的倒数第二段,不仅附加aggregateRating根据你的最后一段,那么最好的我可以上来是

 < div itemscope itemtype =http://schema.org/Productitemref =productMicrodata> 
< div itemprop =aggregateRatingitemscope itemtype =http://schema.org/AggregateRating>
< span itemprop =ratingValue> 79< / span>
< h1 itemscope>< span itemprop =nameid =productMicrodata> Someproductsoandso< / span>< / h1>
< span itemprop =reviewCount> 830< / span>
< / div>
< / div>

h1上的itemscope隐藏了h1的子项与aggregateRating项目,所以name属性将只是通过productMicrodata itemref附加到产品项目。但是,它会创建第三个没有类型的项目。


TL;DR --> I want an itemprop nested in one itemscope to actually be applied to a different itemscope. How do I do that?

Here's a a gist of the code I have (I've removed classes and other extraneous elements on the page to focus on what's important):

<!-- CODE I HAD -->

<div itemscope itemtype="http://schema.org/Product">
  <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
    <span itemprop="ratingValue">79</span>
    <h1 itemprop="name">Someproductsoandso</h1>
    <span itemprop="reviewCount">830</span>
  </div>
</div>

<!-- CODE I NOW HAVE -->

<div itemscope itemtype="http://schema.org/Product" itemref="productMicrodata">
  <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
    <span itemprop="ratingValue">79</span>
    <h1 itemprop="name" id="productMicrodata">Someproductsoandso</h1>
    <span itemprop="reviewCount">830</span>
  </div>
</div>

Basically, I have a product itemscope with a child aggregateRating. Inside that aggregateRating scope I have things like the "ratingValue" and "reviewCount" that I want attached to that, but there's also a "name" value that I want attached to the Product (not the aggregateRating, which also can have a "name" value).

With the first chunk of code I used, google said that my product was missing a name, because the name was being applied to the aggregateRating; with the 2nd, the name is now being applied to both the aggregateRating and the Product. That's not the worst thing, but I'd like it just attached to the aggregateRating; do you know how to solve this without mucking up the current markup organization?

解决方案

Assuming you mean you want it only attached to the Product, as per your penultimate paragraph, and not only attached the aggregateRating as per per your last paragraph, then the best I can come up is

<div itemscope itemtype="http://schema.org/Product" itemref="productMicrodata">
  <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
    <span itemprop="ratingValue">79</span>
    <h1 itemscope><span itemprop="name" id="productMicrodata">Someproductsoandso</span></h1>
    <span itemprop="reviewCount">830</span>
  </div>
</div>

The itemscope on the h1 hides the h1's children from the aggregateRating item, so the name property will only be attached to the Product item via the productMicrodata itemref. It does however, create a third item which has no type.

这篇关于我如何有一个itemprop嵌套在一个itemscope中实际上应用于不同的itemscope?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 21:44