您是否将Schema Microdata元标记放在html正文中? [英] Do you put Schema Microdata meta tags in the html body?
问题描述
我在互联网和stackoverflow上搜索了很长时间以找到这个问题的答案,并且我发现了一些链接,指出你不应该把meta标签放在body中:
而schema.org网站清楚地显示meta标签直接嵌套在 http://schema.org/AggregateRating
请看在那里发布的示例
客户评论:
< div itemprop =reviewsitemscope项目类型= http://schema.org/Review >
< span itemprop =name>不是一个快乐的露营者< / span> -
by< span itemprop =author> Ellie< / span> ;,
< meta itemprop =datePublishedcontent =2011-04-01> 2011年4月1日
< div itemprop =reviewRatingitemscope itemtype =http://schema.org/Rating>
< meta itemprop =worstRatingcontent =1>
< span itemprop =bestRating> 5< / span>星级
< / div>
< span itemprop =description>指示灯熄灭,现在我必须更换
它。 < /跨度>
< / div>
< div itemprop =reviewsitemscope itemtype =http://schema.org/Review>
< span itemprop =name>超值购物< / span> -
by< span itemprop =author> Lucas< / span> ;,
< meta itemprop =datePublishedcontent =2011-03-25> 2011年3月25日
< div itemprop =reviewRatingitemscope itemtype =http://schema.org/Rating>
< meta itemprop =worstRatingcontent =1/>
< spanmpng =bestRating> 5< / span>星级
< / div>
< span itemprop =description>非常适合价格的微波炉。它很小,
适合我的公寓。< / span>
< / div>
如果要将元标记保存在< head>
,那么你如何将这两个日期与他们的评论联系起来?
< meta itemprop =datePublishedcontent =2011-04-01>
< meta itemprop =datePublishedcontent =2011-03-25>
这引起了混淆,我想知道如何处理如果一个元
元素
$ b
- 有一个
itemprop
属性和一个内容
属性和 - 没有
名称
属性,没有http-equiv
属性,并且没有charset
属性,
那么这个 meta
在 body
中。 (如果该值为URL,则必须使用链接
。)
为什么?因为 Microdata规范会更改HTML5 。
(请注意, RDFa也会更改HTML5,方法是允许 meta 在
中有些情况下。) body
如果要将
meta
标签保留在< head>
,那么你会如何将这两个日期关联到他们的评论?
你可以使用 itemref
属性:
<!DOCTYPE html>
< html>
< head>
< title>在head< / title>中为meta使用itemref;
< meta itemprop =datePublishedcontent =2011-03-25id =date>
< / head>
< body>
< div itemscope itemtype =http://schema.org/Reviewitemref =date>
< span itemprop =name> ...< / span>
< / div>
< / body>
< / html>
itemref
以空格分隔的列表 id
值,所以您甚至可以引用两个或更多元素。只需将要添加到该项目的所有元素(包含 itemprop
属性)的 id
添加到其< itemref =日期作者评分
。
I have searched for a long time across the internet and stackoverflow for an answer to this question, and I have found links that say that you should not put meta tags in the body:
while the schema.org website clearly shows the meta tags being nested directly in the body http://schema.org/AggregateRating
Just look at the example that is posted there
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>
If you were to keep the meta tags in the <head>
, then how would you relate these two dates to their reviews?
<meta itemprop="datePublished" content="2011-04-01">
<meta itemprop="datePublished" content="2011-03-25">
This is causing confusion and I would like to know how to do it properly.
If a meta
element
- has an
itemprop
attribute and acontent
attribute, and - has no
name
attribute, nohttp-equiv
attribute, and nocharset
attribute,
then it’s valid to have this meta
in the body
. (If the value is a URL, you must use link
instead.)
Why? Because the Microdata specification changes HTML5.
(Note that RDFa also changes HTML5 by allowing meta
in the body
in some cases.)
If you were to keep the
meta
tags in the<head>
, then how would you relate these two dates to their reviews?
You could 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
takes a space-separated list of id
values, so you can even reference two or more elements. Just add the id
of all elements (containing itemprop
attributes) that should be added to the item to its itemref
attribute, e.g.: itemref="date author rating"
.
这篇关于您是否将Schema Microdata元标记放在html正文中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!