首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >schema.org项目参考问题

schema.org项目参考问题
EN

Stack Overflow用户
提问于 2017-01-25 08:06:13
回答 1查看 678关注 0票数 0

我正忙着在一个关于软件应用程序的网站上添加微数据(schema.org)。

我尝试一次(在可能的情况下)添加元数据并引用元数据,而不是重复重复代码。

这就是我还有疑问的地方:

如何正确引用其他元数据而不将元数据添加到页面本身?让我举个例子:首先,我尝试了这个:

代码语言:javascript
复制
<!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“的范围内。(谷歌测试工具抱怨说,因为一些来自“SoftwareApplication”的项目对“WebPage”无效)

因此,我想添加一个项目范围并替换以下几行:

代码语言:javascript
复制
<div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1"> 
<!-- ... -->
<div id="microdataMyProduct1">
<!-- ... -->

有以下几行:

代码语言:javascript
复制
<div itemscope itemtype="http://schema.org/SoftwareApplication" itemref="microdataMyProduct1">
<!-- ... -->
<div itemscope itemtype="http://schema.org/SoftwareApplication" id="microdataMyProduct1">
<!-- ... -->

问题是,我现在有两个项目范围/项目类型。这是正确的吗?在另一篇堆栈溢出文章中,我看到您不应该将itemref与ID结合使用,而应该引用外部url。我很困惑。

下面是我现在的一个例子(引用其他几个使用itemref的元数据(来自头部内部和微数据本身):

代码语言:javascript
复制
<!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="“属性吗?

EN

回答 1

Stack Overflow用户

发布于 2017-01-25 09:33:14

您不应该为reffering和reffered元素复制itemscope。正确的用法如下:

代码语言:javascript
复制
<!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>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41846318

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档