简体   繁体   English

为Q&A HTML设置微数据的正确方法

[英]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解析器测试您的示例:


name vs. text nametext

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM