【问题标题】:Breadcrumblist last item error from Structured Data Testing Tool: "A value for the item field is required."结构化数据测试工具中的面包屑列表最后一项错误:“需要项字段的值。”
【发布时间】:2019-09-30 17:40:59
【问题描述】:

我们使用BreadcrumbList 提供的示例使用RDFa 格式显示面包屑。当我们将以下示例插入Google's Structured Data Testing Tool 时,我们会收到以下错误。

设置:

  1. 显示BreadcrumbList中的所有items。
  2. 面包屑导航中的最后一个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>

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

项目字段的值是必需的。

我们尝试过但未验证的内容

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

从上面使用&lt;div property="item"&gt; 时的错误消息:

为 item.id 提供的值必须是有效的 URL。

【问题讨论】:

    标签: html schema.org breadcrumbs rdfa


    【解决方案1】:

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

    所以,只需将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>

    【讨论】:

    • 使用 &lt;div&gt; 元素将 href 更改为 resource 完成了这项工作,并且还在结构化数据工具中进行了验证。
    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      当您不想将面包屑的最后一个元素设置为超链接时,就会出现问题,在大多数情况下,超链接只是指向页面本身的链接。在这种情况下,为避免 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>

      【讨论】:

        猜你喜欢
        • 2016-08-26
        • 2017-06-18
        • 2013-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多