【问题标题】:Getting correct schema to fix "The itemprop attribute was specified, but the element is not a property of any item."获取正确的架构以修复“指定了 itemprop 属性,但该元素不是任何项目的属性。”
【发布时间】:2015-12-05 19:22:55
【问题描述】:

我正在尝试让这些元标记与社交媒体一起使用,但我不断收到来自 W3C 验证器的错误:

itemprop 属性已指定,但该元素不是任何项目的属性。

我尝试输入itemscope itemtype="http://schema.org/Products,但这只会产生更多错误。这是我的 HTML 源代码:

<!DOCTYPE html>
  <head>
    <meta charset="utf-8">  
    <meta name="language" content="english"> 
    <meta name="keywords" content="'.$keywords.'">

    <meta property="og:type" content="website" />
    <meta property="og:image" content="'.$meta_image.'"/>
    <meta property="og:url" content="'.$meta_url.'" />
    <meta property="og:site_name" content="'.$meta_name.'"/> 
    <meta property="og:description" name="description" content="'.$description.'" />    
    <meta property="og:title" content="'.$title.'"/>

    <meta itemprop="name" content="'.$title.'">
    <meta itemprop="description" content="'.$description.'">
    <meta itemprop="image" content="'.$meta_image.'">
    <!-- … -->

我的标签有什么问题?

【问题讨论】:

    标签: html meta-tags schema.org w3c-validation microdata


    【解决方案1】:

    Like sideshowbarker explains,每个itemprop 都需要一个属于它的项目(由itemscope 创建)。

    但如果您打算使用一个词汇表(如 Schema.org),您还应该在 itemscope 之外添加一个 itemtypeitemtype 属性给出了您应用属性 (= itemprop) 的项目的类型(来自词汇表)(= itemscope)。

    您说您尝试添加类型http://schema.org/Products,但此类型不存在。如果您的意思是 http://schema.org/Product,则可以将以下内容添加到您的 htmlhead 元素中:

    <head itemscope itemtype="http://schema.org/Product">
      <meta itemprop="name" content="'.$title.'">
      <meta itemprop="description" content="'.$description.'">
      <link itemprop="image" href="'.$meta_image.'">
    </head>
    

    (请注意,如果值为 URI,则 must uselink 元素而不是 meta 元素;我为 image 属性相应地更改了它。)

    【讨论】:

      【解决方案2】:

      添加具有itemscope 属性的html 元素,如下所示:

      <!DOCTYPE html>
      <html itemscope>
        <head>
          <meta charset="utf-8">  
          …
          <meta itemprop="name" content="'.$title.'">
          …
      

      顺便说一句,您也可以省略head 开始标记,并且您应该始终在每个HTML 文档中指定title;所以:

      <!DOCTYPE html>
      <html itemscope>
        <meta charset="utf-8">
        <title>Products</title>
        …
        <meta itemprop="name" content="'.$title.'">
        …
      

      您需要itemscope 属性的原因是因为itemscope 属性实际上是创建项目

      换句话说,没有itemscope,你实际上没有一个项目——相反,你只有一堆与任何东西无关的属性。

      并且通过在html 元素上指定itemscope 属性,文档的意思基本上类似于,此处指定的属性的范围是整个文档。,或者此处指定的属性适用于整个文档。,

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-05-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多