结构化数据测试工具中的面包屑列表最后一项错误:"A value for the item field is required."

Breadcrumblist last item error from Structured Data Testing Tool: "A value for the item field is required."

我们使用 RDFa 格式使用 BreadcrumbList. When we insert the following example into Google's Structured Data Testing Tool 提供的示例显示面包屑,我们得到以下错误。

设置:

  1. 显示 BreadcrumbList.
  2. 中的所有 item
  3. 面包屑中的最后 item 以纯文本显示。

使用RDFa格式时,最后item的正确格式是什么?

示例代码

<ol vocab="http://schema.org/" typeof="BreadcrumbList">
  <li property="itemListElement" typeof="ListItem">
    <a property="item" typeof="WebPage" href="https://example.com/dresses">
     <span property="name">Dresses</span></a>
     <meta property="position" content="1">
  </li>
  <li property="itemListElement" typeof="ListItem">
    <a property="item" typeof="WebPage" href="https://example.com/foo-bar">
     <span property="name">foo-bar</span></a>
     <meta property="position" content="2">
  </li>
  <li property="itemListElement" typeof="ListItem">
    <span property="name">Real Dresses</span>
    <meta property="position" content="3">
  </li>
</ol>

使用上述代码的最后一项的错误消息:

A value for the item field is required.

我们尝试但未验证的内容

<ol vocab="http://schema.org/" typeof="BreadcrumbList">
  <li property="itemListElement" typeof="ListItem">
    <a property="item" typeof="WebPage" href="https://example.com/dresses">
      <span property="name">Dresses</span></a>
    <meta property="position" content="1">
  </li>
  <li property="itemListElement" typeof="ListItem">
    <a property="item" typeof="WebPage" href="https://example.com/foo-bar">
      <span property="name">foo-bar</span></a>
    <meta property="position" content="2">
  </li>
  <li property="itemListElement" typeof="ListItem">
    <div property="item">
      <span property="name">Real Dresses</span>
    </div>
    <meta property="position" content="3">
  </li>
</ol>

从上面使用 <div property="item"> 时的错误消息:

The value provided for item.id must be a valid URL.

最后一项(针对当前页面)仍然代表一个网页,即使您不想显示超链接也是如此。

因此,只需将 typeof="WebPage" 添加到最后一项的 div 即可:

<div property="item" typeof="WebPage">

您仍然可以使用 resource 属性提供最后一项的 URI(不显示它):

<div property="item" typeof="WebPage" resource="https://example.com/real-dresses">

这导致:

    <ol vocab="http://schema.org/" typeof="BreadcrumbList">

      <li property="itemListElement" typeof="ListItem">
        <a property="item" typeof="WebPage" href="https://example.com/dresses">
          <span property="name">Dresses</span></a>
        <meta property="position" content="1">
      </li>

      <li property="itemListElement" typeof="ListItem">
        <a property="item" typeof="WebPage" href="https://example.com/foo-bar">
          <span property="name">foo-bar</span></a>
        <meta property="position" content="2">
      </li>

      <li property="itemListElement" typeof="ListItem">
        <div property="item" typeof="WebPage" resource="https://example.com/real-dresses">
          <span property="name">Real Dresses</span>
        </div>
        <meta property="position" content="3">
      </li>

    </ol>

当您不想使面包屑的最后一个元素成为超 link 时,问题就会出现,这在大多数情况下只是页面本身的 link。在这种情况下,为了避免来自 Google 的结构化数据测试工具的错误,您也可以自由使用 json-ld

HTML

<ol>
  <li>
    <a href="https://example.com/dresses">
      <span>Dresses</span></a>      
  </li>
  <li>
    <a href="https://example.com/foo-bar">
      <span>foo-bar</span></a>      
  </li>
  <li>
    <div>
      <span>Real Dresses</span>
    </div>      
  </li>
</ol>

JSON+LD

<script type="application/ld+json">
{
  "@context": "https://schema.org/", 
  "@type": "BreadcrumbList", 
  "itemListElement": [{
    "@type": "ListItem", 
    "position": 1, 
    "name": "Dresses",
    "item": "https://example.com/dresses"  
  },{
    "@type": "ListItem", 
    "position": 2, 
    "name": "foo-bar",
    "item": "https://example.com/foo-bar"  
  },{
    "@type": "ListItem", 
    "position": 3, 
    "name": "Real Dresses",
    "item": "https://example.com/real-dresses"  
  }]
}
</script>

我在我的本地项目中遇到了同样的问题:

<a href="http://localhost:4356/dresses" itemprop="item">
<span itemprop="name">dresses</span>
<meta itemprop="position" content="2">
</a>

抛出错误:项目字段的值是必需的。

对我来说,通过为 itemprop 提供有效的 URL 来解决:

<a href="https://example.com/dresses" itemprop="item">
<span itemprop="name">dresses</span>
<meta itemprop="position" content="2">
</a>