我有一个元素在我的网站,显示我的网站的最后更新。
我目前的网站结构如下:
<body itemscope itemtype="http://schema.org/webpage"
<div itemscope itemtype="http://schema.org/WPSideBar>
<div>...some text...</div>
<div>last update: 23/1/2014</div> //last update for whole site
<div/>
</body>最后一次更新是为整个网站,而不是为侧边栏!我能用itemtype两次来解决这个问题吗?
例如,你认为这是正确的吗?
<body itemscope itemtype="http://schema.org/webpage"
<div itemscope itemtype="http://schema.org/WPSideBar>
<div>...some text...</div>
<div itemscope itemtype="http://schema.org/webpage">
<span itemscope="name">last update: </span>
<time itemprop="datePublished" datetime="2014-01-23 13:52:00">23/1/2014</time>
</div>
<div/>
</body>发布于 2014-03-10 13:25:37
不,您的不应该添加了几个项目,它们在相同的页面上大致相同。
如果datePublished是整个页面的发布日期,则必须嵌套在WebPage下而不是WPSideBar下。
如果不能将itemref属性直接嵌套在WebPage下,您可以使用它,但仍然必须将其从WPSideBar中删除。除非您还希望此日期与WPSideBar相关联。如果是这样的话,你可以用:
<!-- here the 'datePublished' applies to both, the WebPage *and* the WPSideBar -->
<div itemscope itemtype="http://schema.org/WebPage" itemref="foobar">
<div itemscope itemtype="http://schema.org/WPSideBar">
<time itemprop="datePublished" datetime="2014-01-23 13:52:00" id="foobar">23/1/2014</time>
</div>
</div>(请注意,这是http://schema.org/WebPage,而不是http://schema.org/webpage。)
发布于 2015-07-29 15:50:49
您可以多次使用相同的元素或模式,例如在一个网页中有多个产品,但在这种情况下,您将错误地标记页面上有两个WebPage元素。相反,您只需要一个,但是要在中间处理WPSideBar。根据您的描述,dateModified听起来比datePublished更好选择。这段代码使用hasPart在WebPage中嵌套WPSideBar。
<body itemscope itemtype="http://schema.org/WebPage">
<div itemprop="hasPart" itemscope itemtype="http://schema.org/WPSideBar">
<div>...some text...</div>
<span itemscope="name">last update: </span>
<meta itemprop="dateModified" content="2014-01-23 13:52:00"/>
<time>23/1/2014</time> //last update for whole site
</div>
</div>
</body>的结果
WebPage
hasPart [WPSideBar]:
dateModified: 2014-01-23T13:52:00 这只设置了dateModified of WPSideBar。将WebPage元素的日期设置为更明智的方法是将此WPSideBar行从上面的代码和<span>标记中移除,该标记除了命名侧栏之外什么也不做:
<div itemprop="hasPart" itemscope itemtype="http://schema.org/WPSideBar>如果这两个日期可能不同,那么您可以保留上面的行,并使用以下代码
<body itemscope itemtype="http://schema.org/WebPage"><meta itemprop="dateModified" content="2014-01-20 00:00:00"/>
<div itemprop="hasPart" itemscope itemtype="http://schema.org/WPSideBar">
<div>...some text...</div>
<span itemscope="name">last update: </span>
<meta itemprop="dateModified" content="2014-01-23 13:52:00"/>
<time>23/1/2014</time> //last update for whole site
</div>
</div>
</body>WebPage
dateModified: 2014-01-20T13:00:00
hasPart [WPSideBar]:
dateModified: 2014-01-23T13:52:00没有
的hasPart
WebPage
dateModified: 2014-01-20T13:00:00
WPSideBar
dateModified: 2014-01-23T13:52:00WPSideBar是一个WebPageElement,它可以通过使用itemprop="hasPart"链接(嵌套在WebPage中)--这是从CreativeWork继承的属性。这是结构化数据的嵌套。
您的日期是一种非标准格式,所以我使用了一个不可见自关闭元标记以正确的格式表示此日期,这是隐藏结构化数据的允许原因之一。您最初使用的是"datetime“,而不是"content”。
原始代码中有几个语法错误,包括未关闭的<body>标记,下一次在创建结构化数据问题之前使用HTML验证器/linter--这将节省大量整理结构化数据错误的工作,这些错误最终不是由结构化数据引起的。
https://webmasters.stackexchange.com/questions/59286
复制相似问题