本文介绍了如何在网站的主页上使用schema.org和JSON-LD标记数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Recently i read a lot about marking structured data using schema.org, the first question is , is it recommended to use json-ld at all? because it seems to be new and is not fully supported yet.My second question is on a home page or archive pages ( generally the pages that we have more than 1 article or product or blog post in them ) how do i use schema.org? for example for a page like this :

<!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>

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

How can i mark structured data using josn-ld and how to relate json objects to <article> tags.

推荐答案

有些消费者支持JSON-LD,有些消费者不喜欢吨。对此没有一般性的答案,这取决于您想要支持的消费者/功能。例如,消费者谷歌 JSON-LD的一些功能,但它的一些其他功能。

Some consumers support JSON-LD, some don’t. There can’t be a general answer to this, it depends on which consumers/features you want to support. For example, the consumer Google recommends JSON-LD for some of their features, but doesn’t support it for some of their other features.

如果页面上有多个实体(就像你的例子中的两篇文章),你只需要提供多个节点。有多种方法可以达到这个目的:

If you have multiple entities on a page (like your two articles from the example), you’d simply provide multiple nodes. There are various ways how to achieve this:


  • 你可以提供 脚本每个节点的元素:

<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "CreativeWork"
}
</script>

<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "CreativeWork"
}
</script>


  • 您可以提供一个脚本元素并使用数组作为 @graph 的值(为所有节点共享 @context ):

  • You could provide one script element and use an array as value for @graph (sharing the @context for all nodes):

    <script type="application/ld+json">
    {
      "@context": "http://schema.org/",
      "@graph": 
      [
        {
           "@type": "CreativeWork"
        },
        {
           "@type": "CreativeWork"
        }
      ]
    }
    </script>
    


  • 允许其他人区分节点(和做出他们自己关于他们的陈述),你可以给每个节点一个带有。

    To allow others to differentiate the nodes (and make their own statements about them), you could give each node a URI with the @id keyword.

    这篇关于如何在网站的主页上使用schema.org和JSON-LD标记数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-22 22:30