如何在网站主页上使用schema.org和JSON-LD标记数据

Ami*_*min 0 html5 schema.org json-ld

最近,我读了很多有关使用schema.org标记结构化数据的信息,第一个问题是,建议完全使用它json-ld吗?因为它似乎是新的,尚未得到完全支持。我的第二个问题是在主页或存档页面(通常是其中包含多个文章或产品或博客文章的页面)上,我如何使用schema.org?例如这样的页面:

<!DOCTYPE html>
<html>
    <head>
        <title>Blog Home Page</title>
    </head>

    <body>
        <h1>Blog title</h1>


        <!-- this needs schema.org -->
        <article>
            <h2>Article title</h2>
            Writtem by <span>Authorname</span> on <time datetime="">21 april</time>

            <p>
                Some text
            </p>

            Rated : 
            <div class="star-rate">
                <span class="star full">
                <span class="star full">
                <span class="star full">
                <span class="star half">
                <span class="star empty">
            </div>

            By <span>5</span> users.
        </article>

        <article>
            <h2>Article title</h2>
            Writtem by <span>Authorname</span> on <time datetime="">21 april</time>

            <p>
                Some text
            </p>

            Rated : 
            <div class="star-rate">
                <span class="star full">
                <span class="star full">
                <span class="star full">
                <span class="star half">
                <span class="star empty">
            </div>

            By <span>5</span> users.
        </article>
        <!-- and more articles to go -->
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我如何使用josn-ld标记结构化数据以及如何将json对象与<article>标签相关联。

uno*_*nor 5

有些使用者支持JSON-LD,有些则不支持。对此没有一个普遍的答案,这取决于您要支持哪些消费者/功能。例如,消费者Google 建议将 JSON-LD用于其某些功能,但不支持其某些其他功能。

如果页面上有多个实体(例如示例中的两篇文章),则只需提供多个节点。有多种方法可以实现此目的:

  • 您可以为每个节点提供一个单独的 script元素:

    <script type="application/ld+json">
    {
      "@context": "http://schema.org/",
      "@type": "CreativeWork"
    }
    </script>
    
    <script type="application/ld+json">
    {
      "@context": "http://schema.org/",
      "@type": "CreativeWork"
    }
    </script>
    
    Run Code Online (Sandbox Code Playgroud)
  • 您可以提供一个script元素并使用数组作为值@graph@context为所有节点共享):

    <script type="application/ld+json">
    {
      "@context": "http://schema.org/",
      "@graph": 
      [
        {
           "@type": "CreativeWork"
        },
        {
           "@type": "CreativeWork"
        }
      ]
    }
    </script>
    
    Run Code Online (Sandbox Code Playgroud)

为了允许其他人区分节点(并做出关于它们的声明),可以为每个节点提供一个带有@id关键字的URI 。