获取正确的模式以修复“已指定itemprop属性,但该元素不是任何项目的属性”的错误。

3
我想让这些元标记与社交媒体一起使用,但是我不断收到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.'">
    <!-- … -->

我的标签出了什么问题?

2个回答

6

添加一个带有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 属性,文档所表达的基本意思是:像这样指定的属性的范围是整个文档,或者说,这里指定的属性适用于整个文档。

3

就像sideshowbarker所解释的那样, 每个itemprop都需要一个属于它的项目(由itemscope创建)。

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

你说你试图添加类型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,您必须使用link元素而不是meta元素; 我已经针对image属性进行了更改。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接