您是否将架构微数据元标记放在 html 正文中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10279277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Do you put Schema Microdata meta tags in the html body?
提问by Timo Huovinen
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:
我在 Internet 和 stackoverflow 上搜索了很长时间来寻找这个问题的答案,我找到了一些链接,说你不应该在正文中放置元标记:
while the schema.org website clearly shows the meta tags being nested directly in the body http://schema.org/AggregateRating
而 schema.org 网站清楚地显示了直接嵌套在正文中的元标记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">
如果您要将元标记保留在 中<head>
,那么您将如何将这两个日期与他们的评论联系起来?
<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.
这引起了混乱,我想知道如何正确地做到这一点。
回答by unor
If a meta
element
如果一个meta
元素
- has an
itemprop
attribute and acontent
attribute, and - has no
name
attribute, nohttp-equiv
attribute, and nocharset
attribute,
- 有一个
itemprop
属性和一个content
属性,并且 - 没有
name
属性,没有http-equiv
属性,也没有charset
属性,
then it's valid to have this meta
in the body
. (If the value is a URL, you must use link
instead.)
那么meta
在body
. (如果值为 URL,则必须link
改用。)
Why? Because the Microdata specification changes HTML5.
为什么?因为微数据规范改变了 HTML5。
(Note that RDFa also changes HTML5 by allowing meta
in the body
in some cases.)
(请注意,RDFa的也允许改变HTML5meta
在body
某些情况下)。
If you were to keep the
meta
tags in the<head>
, then how would you relate these two dates to their reviews?
如果您将
meta
标签保留在 中<head>
,那么您将如何将这两个日期与他们的评论联系起来?
You could use the itemref
attribute:
你可以使用itemref
属性:
<!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"
.
itemref
采用空格分隔的id
值列表,因此您甚至可以引用两个或多个元素。只需将应添加到项目id
的所有元素(包含itemprop
属性)添加到其itemref
属性中,例如:itemref="date author rating"
。
回答by Gruber
Remember also that it's possible to totally avoid HTML markup and use JSON-LD markup entirely contained in the anywherein the HTML document (even dynamically injected!)like this:<head>
还请记住,完全避免 HTML 标记并使用完全包含在HTML 文档<head>
中的任何位置(甚至是动态注入的!)的JSON-LD 标记是可能的,如下所示:
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Restaurant",
"name": "Fondue for Fun and Fantasy",
"description": "Fantastic and fun for all your cheesy occasions",
"openingHours": "Mo,Tu,We,Th,Fr,Sa,Su 11:30-23:00",
"telephone": "+155501003333",
"menu": "http://example.com/menu"
}
</script>
have a look at the examples in schema.org, they usually contain JSON example markups like this https://schema.org/Restaurant.
查看schema.org中的示例,它们通常包含像https://schema.org/Restaurant这样的 JSON 示例标记。
Here is another good article about it http://www.seoskeptic.com/json-ld-google-knowledge-graph-schema-org-seo/
这是另一篇关于它的好文章http://www.seoskeptic.com/json-ld-google-knowledge-graph-schema-org-seo/
回答by superhero
What I can read from whatwg.org it's correct to use in body: http://www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#the-meta-element
我可以从 whatwg.org 读到的内容在正文中使用是正确的:http: //www.whatwg.org/specs/web-apps/current-work/multipage/semantics.html#the-meta-element
I use meta tags in the body of my blogg to specify the "datePublished" and "dateUpdated" properties. Googles Rich Snippets Testing Tooltells me it's correct and w3c validates the code.
我在博客正文中使用元标记来指定“datePublished”和“dateUpdated”属性。Google 的Rich Snippets 测试工具告诉我它是正确的并且 w3c 验证了代码。
回答by Rowe Morehouse
You can use:
您可以使用:
<meta itemprop="">
in the body of the page to do schema.org semantic markup that is machine readable (by robots, for SEO, for instance) even if you don't want to display the actual text (product name, for example) on the page.
即使您不想在页面上显示实际文本(例如产品名称),也可以在页面正文中执行机器可读的 schema.org 语义标记(例如,通过机器人,用于 SEO)。
see: http://schema.org/docs/gs.html#advanced_missing
请参阅:http: //schema.org/docs/gs.html#advanced_missing
Sometimes, a web page has information that would be valuable to mark up, but the information can't be marked up because of the way it appears on the page. The information may be conveyed in an image (for example, an image used to represent a rating of 4 out of 5) or a Flash object (for example, the duration of a video clip), or it may be implied but not stated explicitly on the page (for example, the currency of a price).
有时,网页中包含有价值的信息需要标记,但由于信息在页面上的显示方式而无法标记。信息可能在图像(例如,用于表示 5 分中的 4 分的图像)或 Flash 对象(例如,视频剪辑的持续时间)中传达,或者可能是隐含的但未明确说明在页面上(例如,价格的货币)。
回答by ladar
I do it this way:
我这样做:
<meta id="md_course" itemprop="course" name="course" content="..."/>
<meta id="md_lang" itemprop="language" content="eng"/>
<title id="md_title" itemprop="title" >Motivation and Course Overview</title>
</head>
<body itemscope itemtype=".../Presentation" itemref="md_course md_lang md_title md_field">
回答by HBCondo
When first working with schema.org's microdata, I added the meta tags in the head tag of my web page but when I ran that page against Google's Rich Snippets Testing Tool, the data was not extracted. I then moved the meta tags into the body of the page and the data was shown as being extracted.
第一次使用 schema.org 的微数据时,我在网页的 head 标记中添加了元标记,但是当我针对Google 的 Rich Snippets Testing Tool运行该页面时,未提取数据。然后我将元标记移动到页面正文中,数据显示为已提取。