为Q& A HTML设置微数据的正确方法 [英] Right way to set microdata for Q&A HTML
问题描述
说一个简单的问答HTML并想添加微数据,应该如何进行?
Say one has a simple question and answer HTML and would like to add microdata, how should one proceed?
<h2>My Question</h2>
<p>My Answer</p>
我知道 schema.org 的示例,但是我不太清楚.看起来好像太过分了.我需要一个简单的解决方案.我可以这样吗?
I am aware of the schema.org example, but I don't find it very clear. 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>
使用 itemprop ="name"
正确的方法来说明问题是什么吗?上面提到的schema.org示例中的 itemprop ="name"
和 itemprop ="text"
有什么区别?
Is using itemprop="name"
the right way to tell what the question is? What is the difference between itemprop="name"
and itemprop="text"
in the schema.org example mentioned above?
推荐答案
在您的第一个示例中,微数据解析器将仅了解到存在问题
和 Answer
项,没有任何进一步的内容.微数据没有指定必须考虑具有 itemscope
属性的HTML元素的内容,它只关心
From your first example, Microdata parsers will only learn that there is a Question
and an Answer
item, without any further content. Microdata doesn’t specify that the content of HTML elements with itemscope
attributes has to be considered, it only cares about property values.
使用某些在线微数据解析器来测试您的示例:
Testing your example with some online Microdata parsers:
-
W3C的 RDF Distiller的微数据提取了该RDF(在Turtle中):
W3C’s Microdata to RDF Distiller extracts this RDF (in Turtle):
<> md:item ( [ a schema:Question ] [ a schema:Answer ] );
rdfa:usesVocabulary schema: .
结构化数据Linter 具有几乎相同的输出.
The Structured Data Linter has almost the same output.
Yandex的结构化数据验证器具有类似的输出.
Yandex’s Structured data validator has similar output.
Google的结构化数据测试工具不会提取任何内容./p>
Google’s Structured Data Testing Tool doesn’t extract anything.
对于这个问题,名称
将是为Q& A HTML设置微数据的正确方法",而 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 …").
如果整个问题仅由一条短线组成,我将使用 text
属性而不是 name
(*).如果需要,名称
原则上也可以类似于问题1".
If the whole question consists only of such a single, short line, I’d use the text
property instead of name
(*). name
could, principally, also be something like "Question 1", if you want/need it.
但是您也可以将两个属性都用于一个简短的问题,即 itemprop ="name text"
,但这可能不是很优雅(但是如果您知道一些数据使用者使用 name
属性).
But you could also use both properties for a short question, i.e., 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).
* 答案
的示例也使用了 text
(并且没有 name
).
* The example for Answer
also uses text
(and has no name
).
您可能还想使用Question的 suggestedAnswer
属性和/或Answer的<一个href ="http://schema.org/parentItem" rel ="nofollow noreferrer"> parentItem
属性来关联这两个项目.
You might also want to use Question’s suggestedAnswer
property and/or Answer’s parentItem
property to relate these two items.
因此,一个简短的问题可能看起来像:
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>
这篇关于为Q& A HTML设置微数据的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!