2017-01-25 83 views
0

我忙於向網站添加關於軟件應用程序的微數據(schema.org)。schema.org itemref問題

而不是重複我自己的重複代碼我嘗試添加元數據一次(如果可能)並參考它。

這是我仍然有問題:

你如何正確地引用到其他元數據而不被添加到頁面本身的元數據? 讓我舉個例子:首先,我想這:

<!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> 

這上面的代碼也增加了產品的微觀數據itemprop的到「網頁」的範圍。 (其中谷歌測試工具抱怨,因爲一些itemprop的從「SoftwareApplication」不適用於「網頁」)

所以我想補充一個項目的範圍和更換這些線路:

<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的組合,但引用到外部網址。我很困惑。

下面是一個例子,我現在(使用的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 =「」屬性,正確使用

+0

相關:[?如何過的itemscope分成多個HTML元素(http://stackoverflow.com/q/29135360/1591669) – unor

回答

0

你不應該爲reffering和下文稱元素複製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>

+1

你確定嗎?因爲現在您將「microdataMyProduct1」的屬性添加到WebPage。這會產生像「applicationCategory:BusinessApplication(Google無法識別WebPage類型的對象的屬性applicationCategory)」的錯誤。 您可以測試您的代碼片段:https://search.google.com/structured-data/testing-工具 你現在正面臨着我在帖子中提到的問題... – juFo

+0

好吧,我已經編輯好了代碼,'WebSite'被刪除,'WebPage'被重新定位 – br3t

+0

這是一個臨時修復,因爲其他對象可能是添加/嵌套導致相同的問題... – juFo