我正忙着将微数据(schema.org)添加到有关软件应用程序的网站。
我没有在重复代码方面重复自己,而是尝试一次添加元数据(如果可能)并引用它。
这是我仍然有疑问的地方:
如果没有将元数据添加到页面本身,您如何正确引用其他元数据? 让我举个例子:首先我尝试了这个:
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/WebSite" lang="en">
<body itemprop="mainEntity" itemscope itemtype="http://schema.org/WebPage">
<div class="main">
<div class="container">
<div class="row">
<div class="col-md-12">
<!-- info about product and reference to the metadata -->
<div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
<!-- product info on website -->
</div>
</div>
</div>
</div>
</div>
<!-- this metadata gets also added to the WebPage -->
<div id="microdataMyProduct1">
<meta itemprop="name" content="My Product 1" />
</div>
</body>
</html>
但上面的代码还将产品的微数据迭代添加到&#34; WebPage&#34;的范围内。 (谷歌测试工具抱怨的地方,因为软件应用程序&#39;中的某些迭代不适用于网页&#39;)
所以我想添加一个项目范围并替换这些行:
<div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
<!-- ... -->
<div id="microdataMyProduct1">
<!-- ... -->
这些行:
<div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
<!-- ... -->
<div itemscope itemtype="http://schema.org/SoftwareApplication" id="microdataMyProduct1">
<!-- ... -->
问题是我现在有两个物品望远镜/物品类型。它是否正确? 在另一个stackoverflow帖子中,我已经读过你不应该将itemref与ID结合使用,而是引用外部URL。我很困惑。
这是我现在的一个例子(使用itemref引用其他几个元数据(从头部内部和微数据本身):
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/WebSite" lang="en">
<head>
<meta name="author" content="Company 1">
<meta itemprop="author" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1">
<meta itemprop="about" itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
<!-- ... -->
</head>
<body itemprop="mainEntity" itemscope itemtype="http://schema.org/WebPage">
<div itemprop="hasPart" itemscope itemtype="http://schema.org/WPHeader">
<nav class="navbar" itemprop="hasPart" itemscope itemtype="http://schema.org/SiteNavigationElement">
<!-- ... -->
</nav>
</div>
<div class="main">
<div class="container">
<div class="row">
<div class="col-md-12">
<!-- another second product on the page -->
<div itemscope itemtype="http://schema.org/SoftwareApplication">
<h3 itemprop="name">Second Product</h3>
<meta itemprop="applicationCategory" content="BusinessApplication" />
<meta itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
<meta itemprop="producer" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
<meta itemprop="provider" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataOtherCompany" />
<!-- ... -->
</div>
</div>
</div>
</div>
</div>
<div class="footer" itemprop="hasPart" itemscope itemtype="http://schema.org/WPFooter">
</div>
<!-- Product 1 microdata -->
<!-- ##################### -->
<div hidden class="hidden" itemscope itemtype="http://schema.org/SoftwareApplication" id="microdataMyProduct1">
<meta itemprop="name" content="My Product 1" />
<meta itemprop="applicationCategory" content="BusinessApplication" />
<meta itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
<meta itemprop="producer" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
<meta itemprop="provider" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataOtherCompany" />
</div>
<!-- Company 1 microdata -->
<!-- ################### -->
<div hidden class="hidden" itemscope itemtype="http://schema.org/LocalBusiness" id="microdataCompany1">
<meta itemprop="name" content="Company 1">
<!-- ... -->
<div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
<link itemprop="dayOfWeek" href="http://schema.org/Monday" />
<time itemprop="opens" content="8:00:00" />
<time itemprop="closes" content="12:30:00" />
<time itemprop="opens" content="13:30:00" />
<time itemprop="closes" content="18:00:00" />
</div>
<div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
<link itemprop="dayOfWeek" href="http://schema.org/Tuesday" />
<time itemprop="opens" content="8:00:00" />
<time itemprop="closes" content="12:30:00" />
<time itemprop="opens" content="13:30:00" />
<time itemprop="closes" content="18:0:00" />
</div>
</div>
<!-- Other Company microdata -->
<!-- ######################## -->
<div hidden class="hidden" itemscope itemtype="http://schema.org/LocalBusiness" id="microdataOtherCompany">
<meta itemprop="name" content="Other Company">
<meta itemprop="legalName" content="Other Company Ltd.">
<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<meta itemprop="streetAddress" content="FooStreet">
<!-- ... -->
</div>
</div>
</body>
</html>
网站上有关产品的网页是否正确使用微数据? 是itemref =&#34;&#34;属性是否正确使用?
答案 0 :(得分:0)
您不应复制itemscope
用于复制和引用元素。正确的用法是这样的:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="author" content="Company 1">
</head>
<body>
<main itemprop="mainEntity" itemscope itemtype="http://schema.org/WebPage">
<div itemprop="hasPart" itemscope itemtype="http://schema.org/WPHeader">
<nav class="navbar" itemprop="hasPart" itemscope itemtype="http://schema.org/SiteNavigationElement">
</nav>
</div>
<div class="main">
<div class="container">
<div class="row">
<div class="col-md-12">
<div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
</div>
<!-- another second product on the page -->
<div itemscope itemtype="http://schema.org/SoftwareApplication">
<h3 itemprop="name">Second Product</h3>
<meta itemprop="applicationCategory" content="BusinessApplication" />
<meta itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
<meta itemprop="producer" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
<meta itemprop="provider" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataOtherCompany" />
</div>
</div>
</div>
</div>
</div>
<div class="footer" itemprop="hasPart" itemscope itemtype="http://schema.org/WPFooter">
</div>
</main>
<!-- Product 1 microdata -->
<!-- ##################### -->
<div hidden class="hidden" id="microdataMyProduct1">
<meta itemprop="name" content="My Product 1" />
<meta itemprop="applicationCategory" content="BusinessApplication" />
<meta itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
<meta itemprop="producer" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataCompany1" />
<meta itemprop="provider" itemscope itemtype="http://schema.org/LocalBusiness" itemref="microdataOtherCompany" />
<meta itemprop="image" content="http://example.com/example.gif" />
</div>
<!-- Company 1 microdata -->
<!-- ################### -->
<div hidden class="hidden" id="microdataCompany1">
<meta itemprop="name" content="Company 1">
<meta itemprop="image" content="http://example.com/example.gif" />
<div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
<link itemprop="dayOfWeek" href="http://schema.org/Monday" />
<time itemprop="opens" content="8:00:00" />
<time itemprop="closes" content="12:30:00" />
<time itemprop="opens" content="13:30:00" />
<time itemprop="closes" content="18:00:00" />
</div>
<div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
<link itemprop="dayOfWeek" href="http://schema.org/Tuesday" />
<time itemprop="opens" content="8:00:00" />
<time itemprop="closes" content="12:30:00" />
<time itemprop="opens" content="13:30:00" />
<time itemprop="closes" content="18:0:00" />
</div>
</div>
<!-- Other Company microdata -->
<!-- ######################## -->
<div hidden class="hidden" id="microdataOtherCompany">
<meta itemprop="name" content="Other Company">
<meta itemprop="image" content="http://example.com/example.gif" />
<meta itemprop="legalName" content="Other Company Ltd.">
<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
<meta itemprop="streetAddress" content="FooStreet">
</div>
</div>
</body>
</html>