Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
893 views
in Technique[技术] by (71.8m points)

javascript - How to markup the last non linking item in breadcrumbs list using JSON-LD

I am using structured data for my breadcrumbs trail. I'm refering to this documentation:

https://developers.google.com/structured-data/breadcrumbs

I have built up a breadcrumbs list. I also display the last item that refers to the current page but this is not a link but just plain text. This is what my HTML markup looks like:

<ol class="breadcrumb">
     <li><a href="http://www.example.com/">Home</a></li>
     <li><a href="http://www.example.com/brands">Brands</a></li>
     <li class="active">My Brand</li>
</ol>

I have opted to use JSON-LD to markup my breadcrumbs trail. I'm not sure how to markup the last item in my breadcrumbs list seeing that it is not a link? Am I supposed to leave it out? This is what I currently have:

<script type="application/ld+json">
{
     "@context": "http://schema.org",
     "@type": "BreadcrumbList",
     "itemListElement": [{
          "@type": "ListItem",
          "position": 1,
          "item": {
               "@id": "http://www.example.com/",
               "name": "Home"
          }
     }, {
          "@type": "ListItem",
          "position": 2,
          "item": {
               "@id": "http://www.example.com/brands",
               "name": "Brands"
          }
     }]
}
</script>

Do I need to add the last item like I did with the other 2 items, or do I need to leave it? Is it just for the items that have links to it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Of course you can simply provide the ListItem for the last item and omit the @id:

<script type="application/ld+json">
{
     "@context": "http://schema.org",
     "@type": "BreadcrumbList",
     "itemListElement": [{
          "@type": "ListItem",
          "position": 1,
          "item": {
               "@id": "http://www.example.com/",
               "name": "Home"
          }
     }, {
          "@type": "ListItem",
          "position": 2,
          "item": {
               "@id": "http://www.example.com/brands",
               "name": "Brands"
          }
     }, {
          "@type": "ListItem",
          "position": 3,
          "item": {
               "name": "My Brand"
          }
     }]
}
</script>

That is valid JSON-LD and fine according to Schema.org.

However, I would add the URL of the last/current item anyway. In case of RDFa or Microdata, I would have used the link element for the last item’s URL (so the URL is not clickable for human visitors, but bots have more data), but in case of JSON-LD, this problem isn’t relevant in the first place, as the human visitors typically don’t interact with it.

The only conceivable downside could be that a consumer gets confused if the content in the HTML doesn’t match the content in JSON-LD (i.e., the URL for the last item is missing). But I’d consider this risk pretty low, as it should be well known that there are different ways how to handle the last breadcrumb item.


As far as documentation goes, Schema.org only says that the BreadcrumbList is "typically ending with the current page".

And as an example for a consumer, Google says the same for their Breadcrumbs feature:

The breadcrumb trail may include or omit a breadcrumb for the page on which it appears.

But they don’t say anything about the case where the last item is included without its URL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...