gpt4 book ai didi

html - 您是否将 Schema Microdata 元标记放在 html 正文中?

转载 作者:技术小花猫 更新时间:2023-10-29 11:32:40 27 4
gpt4 key购买 nike

我在互联网和 stackoverflow 上搜索了很长时间来寻找这个问题的答案,我找到了一些链接,上面说你不应该在正文中放置元标记:

虽然 schema.org 网站清楚地显示了直接嵌套在正文中的元标记 http://schema.org/AggregateRating

只要看看那里张贴的例子

 Customer reviews:

<div itemprop="reviews" itemscope itemtype="http://schema.org/Review">
<span itemprop="name">Not a happy camper</span> -
by <span itemprop="author">Ellie</span>,
<meta itemprop="datePublished" content="2011-04-01">April 1, 2011
<div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
<meta itemprop="worstRating" content = "1">
<span itemprop="ratingValue">1</span>/
<span itemprop="bestRating">5</span>stars
</div>
<span itemprop="description">The lamp burned out and now I have to replace
it. </span>
</div>


<div itemprop="reviews" itemscope itemtype="http://schema.org/Review">
<span itemprop="name">Value purchase</span> -
by <span itemprop="author">Lucas</span>,
<meta itemprop="datePublished" content="2011-03-25">March 25, 2011
<div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
<meta itemprop="worstRating" content = "1"/>
<span itemprop="ratingValue">4</span>/
<span itemprop="bestRating">5</span>stars
</div>
<span itemprop="description">Great microwave for the price. It is small and
fits in my apartment.</span>
</div>

如果您要将元标记保留在 <head> 中,那么您如何将这两个日期与他们的评论联系起来? <meta itemprop="datePublished" content="2011-04-01"> <meta itemprop="datePublished" content="2011-03-25">

这造成了困惑,我想知道如何正确地做到这一点。

最佳答案

如果 meta元素

  • 有一个itemprop属性和 content属性,和
  • 没有name属性,没有 http-equiv属性,没有 charset属性,

那么这个 meta 是有效的在body . (如果该值为 URL,则为 must use link instead。)

为什么?因为the Microdata specification changes HTML5 .

(注意在某些情况下是 RDFa also changes HTML5 by allowing meta in the body 。)


If you were to keep the meta tags in the <head>, then how would you relate these two dates to their reviews?

你可以 use the itemref attribute :

<!DOCTYPE html>
<html>
<head>
<title>Using itemref for meta in the head</title>
<meta itemprop="datePublished" content="2011-03-25" id="date">
</head>
<body>

<div itemscope itemtype="http://schema.org/Review" itemref="date">
<span itemprop="name">…</span>
</div>

</body>
</html>

itemref采用空格分隔的列表 id值,因此您甚至可以引用两个或多个元素。只需添加 id应添加到项目的所有元素(包含 itemprop 属性)的 itemref属性,例如:itemref="date author rating" .

关于html - 您是否将 Schema Microdata 元标记放在 html 正文中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10279277/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com