简体   繁体   English

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

[英]How to mark data using schema.org and JSON-LD on a website's home page

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? 最近,我读了很多有关使用schema.org标记结构化数据的信息,第一个问题是,是否建议完全使用json-ld 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? 我的第二个问题是在主页或存档页面(通常是其中包含多个文章或产品或博客文章的页面)上,我如何使用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>

How can i mark structured data using josn-ld and how to relate json objects to <article> tags. 我如何使用josn-ld标记结构化数据以及如何将json对象与<article>标签相关。

Some consumers support JSON-LD, some don't. 有些使用者支持JSON-LD,有些则不支持。 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. 例如,消费者Google 建议将 JSON-LD用于某些功能,但不支持其某些其他功能。

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: 有多种方法可以实现此目的:

  • You could provide a separate script element for each node: 您可以为每个节点提供一个单独的 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> 
  • You could provide one script element and use an array as value for @graph (sharing the @context for all nodes): 您可以提供一个script元素,并使用数组作为@graph值(为所有节点共享@context ):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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