[英]Right way to set microdata for Q&A HTML
Say one has a simple question and answer HTML and would like to add microdata, how should one proceed? 假设有一个简单的问题并回答HTML并想添加微数据,应该如何进行?
<h2>My Question</h2>
<p>My Answer</p>
I am aware of the schema.org example, but I don't find it very clear. 我知道schema.org的例子,但我不太清楚。 It looks like overkill.
看起来有点矫枉过正。 I need a simple solution.
我需要一个简单的解决方案 Can I proceed this way?
我可以这样做吗?
<h2 itemscope itemtype="http://schema.org/Question">My Question</h2>
<p itemscope itemtype="http://schema.org/Answer">My Answer</p>
I just want to tell what the question is and what the answer is. 我只想说出问题是什么,答案是什么。 Is this enough for search engines?
这对搜索引擎来说足够了吗? Or should I have something more sophisticated like:
或者我应该有更复杂的东西,如:
<div itemscope itemtype="http://schema.org/Question">
<h2 itemprop="name">My Question</h2>
<p itemscope itemtype="http://schema.org/Answer">My Answer</p>
</div>
Is using itemprop="name"
the right way to tell what the question is? 使用
itemprop="name"
正确的方法来说明问题是什么? What is the difference between itemprop="name"
and itemprop="text"
in the schema.org example mentioned above? 在上面提到的schema.org示例中,
itemprop="name"
和itemprop="text"
之间有什么区别?
From your first example, Microdata parsers will only learn that there is a Question
and an Answer
item, without any further content. 从您的第一个示例开始,Microdata解析器只会知道有一个
Question
和一个Answer
项目,没有任何进一步的内容。 Microdata doesn't specify that the content of HTML elements with itemscope
attributes has to be considered, it only cares about property values . 微数据没有指定必须考虑具有
itemscope
属性的HTML元素的内容,它只关心属性值 。
Testing your example with some online Microdata parsers : 使用一些在线Microdata解析器测试您的示例:
W3C's Microdata to RDF Distiller extracts this RDF (in Turtle): W3C的微型数据到RDF Distiller提取这个RDF(在Turtle中):
<> md:item ( [ a schema:Question ] [ a schema:Answer ] ); rdfa:usesVocabulary schema: .
The Structured Data Linter has almost the same output. 结构化数据锁定器具有几乎相同的输出。
Yandex's Structured data validator has similar output. Yandex的结构化数据验证器具有类似的输出。
Google's Structured Data Testing Tool doesn't extract anything. 谷歌的结构化数据测试工具不提取任何东西。
name
vs. text
name
与text
For this very question, the name
would be "Right way to set microdata for Q&A HTML" and the text
would be the question body ("Say one has a simple question …"). 对于这个问题,
name
将是“为Q&A HTML设置微数据的正确方法”, text
将是问题正文(“Say one有一个简单的问题......”)。
If the whole question consists only of such a single, short line, I'd use the text
property instead of name
(*). 如果整个问题只包含这样一条短线,我会使用
text
属性而不是name
(*)。 name
could, principally, also be something like "Question 1", if you want/need it. 如果你想要/需要,
name
也可以是“问题1”。
But you could also use both properties for a short question, ie, itemprop="name text"
, but this is maybe not very elegant (but it can make sense especially if you know that some data consumer makes use of the name
property). 但是你也可以将这两个属性用于一个简短的问题,即
itemprop="name text"
,但这可能不是很优雅(但是如果你知道某些数据使用者使用了name
属性,它就会有意义)。
* The example for Answer
also uses text
(and has no name
). *
Answer
的示例也使用text
(并且没有name
)。
You might also want to use Question's suggestedAnswer
property and/or Answer's parentItem
property to relate these two items. 您可能还想使用Question的
suggestedAnswer
属性和/或Answer的parentItem
属性来关联这两个项目。
So for a short question it could look like: 所以对于一个简短的问题,它可能看起来像:
<section itemscope itemtype="http://schema.org/Question">
<h2 itemprop="name text">My Question</h2>
<div itemprop="suggestedAnswer" itemscope itemtype="http://schema.org/Answer">
<p itemprop="text">My Answer</p>
</div>
</section>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.