[英]schema.org itemref questions
我正忙於將微數據(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>
但是上面的這段代碼還將產品的微數據項屬性添加到了“ WebPage”的范圍內。 (Google測試工具抱怨的地方,因為“ SoftwareApplication”中的某些itemprop對“ WebPage”無效))
所以我想添加一個項目范圍並替換這些行:
<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">
<!-- ... -->
問題是我現在有兩個itemscopes / itemtypes。 這個對嗎? 在另一篇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 =“”屬性?
您不應該為引用和引用元素重復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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.