如何在 Microdata 中为 FAQ 组件创建标记?

How to create markup for FAQ component in Microdata?

当页面本身不是 FAQ 时,如何为 FAQ 组件创建微数据标记?

以下示例基于 Google Microdata https://developers.google.com/search/docs/advanced/structured-data/faqpage but Rich Results Tool (https://search.google.com/test/rich-results) 似乎根本无法识别。除非 HTML 根元素有额外的属性 <html itemscope itemtype="https://schema.org/FAQPage">,只有在那种情况下它才有效。但我更希望在其他一些页面类型上也有微数据常见问题解答(具有不同的内容),这样这些页面在根目录下会有不同的项目类型。

<div itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
    <h2 itemprop="name">Question 1</h2>
    <div itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
        <div itemprop="text">
            Text text text
        </div>
    </div>
</div>
<div itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
    <h2 itemprop="name">Question 2</h2>
    <div itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
        <div itemprop="text">
            Text text text
        </div>
    </div>
</div>

请试试这个:

<script type="application/ld+json">
    {
    
      "@context": "https://schema.org",
      "@type": "FAQPage",
      "mainEntity": [{
        "@type": "Question",
        "name": "Question 1",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "Answer 1"
        }
      }, {
        "@type": "Question",
        "name": "Question 2",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "Answer 2"
        }
      },
      {
        "@type": "Question",
        "name": "Question 3",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "Answer 3"
        }
      }]
        }
    </script>

请检查:

<div itemscope itemtype="https://schema.org/FAQPage"> 
<div itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
    <h2 itemprop="name">Question 1</h2>
    <div itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
        <div itemprop="text">
            Text text text
        </div>
    </div>
</div>
<div itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
    <h2 itemprop="name">Question 2</h2>
    <div itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
        <div itemprop="text">
            Text text text
        </div>
    </div>
</div>
</div>