简体   繁体   中英

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?

<h2>My Question</h2>
<p>My Answer</p>

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>

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?

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 :


name vs. 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 …").

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.

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).

* The example for Answer also uses text (and has no name ).


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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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