如何格式化创意作品微数据中的关键字?

发布于 2024-12-14 06:32:22 字数 233 浏览 0 评论 0原文

我正在使用 Microdata,并且希望将 Schema.org 的 keywords 用于 CreativeWork

架构指定它应该是文本,但我是否将每个关键字放入 itemprop="keywords" 的单独元素中,还是将它们全部放入一个 keywords 元素中?如果我将它们全部放在一个元素中,我是否使用逗号作为分隔符?

I'm working with Microdata and I want to use Schema.org’s keywords for CreativeWork.

The schema specifies that it should be text but do I put each keyword in a separate element with itemprop="keywords" or do I put them all in one keywords element? If I put them all in one element do I use commas as a separator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

温柔嚣张 2024-12-21 06:32:22

Schema.org 的 keywords 属性 的定义已更改。现在内容如下:

用于描述此内容的关键字或标签。关键字列表中的多个条目通常用逗号分隔。

所以它在微数据中可能看起来像这样:(

<article itemscope itemtype="http://schema.org/BlogPosting">

  <footer>
    <ul itemprop="keywords">
      <li><a href="/tags/foo" rel="tag">foo</a>,</li>
      <li><a href="/tags/bar" rel="tag">bar</a></li>
    </ul>
  </footer>

</article>

示例取自我关于标签的语义标记的相关答案。)

如果您不这样做如果不想在页面上看到逗号,除了正常的标签标记之外,您还可以使用 meta 元素:(

<meta itemprop="keywords" content="foo, bar" />

它是 允许将此 meta 元素放置在“body”中。)

The definition of Schema.org’s keywords property changed. It now reads:

Keywords or tags used to describe this content. Multiple entries in a keywords list are typically delimited by commas.

So it could look like this in Microdata:

<article itemscope itemtype="http://schema.org/BlogPosting">

  <footer>
    <ul itemprop="keywords">
      <li><a href="/tags/foo" rel="tag">foo</a>,</li>
      <li><a href="/tags/bar" rel="tag">bar</a></li>
    </ul>
  </footer>

</article>

(Example taken from my related answer about semantic markup for tags.)

If you don’t want to have commas visible on the page, you could use a meta element in addition to your normal markup for the tags:

<meta itemprop="keywords" content="foo, bar" />

(It’s allowed to place this meta element in the `body´.)

↘人皮目录ツ 2024-12-21 06:32:22

您应该为每个关键字创建一个 itemprop 元素,如下所示:

<div itemscope itemtype="http://schema.org/CreativeWork">
  <span itemprop="name">Resistance 3: Fall of Man</span>
  by <span itemprop="author">Sony</span>.
  Keywords:
  <a href="/tags/game/"><span itemprop="keywords">Game</span></a>,
  <a href="/tags/adult/"><span itemprop="keywords">Adult</span></a>
</div>

You should create an itemprop element for each keyword as follows:

<div itemscope itemtype="http://schema.org/CreativeWork">
  <span itemprop="name">Resistance 3: Fall of Man</span>
  by <span itemprop="author">Sony</span>.
  Keywords:
  <a href="/tags/game/"><span itemprop="keywords">Game</span></a>,
  <a href="/tags/adult/"><span itemprop="keywords">Adult</span></a>
</div>
末骤雨初歇 2024-12-21 06:32:22

我对规范的阅读使我得出这样的结论:每个属性只能有一个 itemprop 属性。

换句话说,我认为为每个关键字创建 itemprop 元素不会创建正确的微数据语法。

我会将每个关键字放在一个以空格分隔的列表中,并使用单个 itemprop:

  <span itemprop="keywords">
  <a href="/tags/game/">Game</a>,
  <a href="/tags/adult/">Adult</a>
  </span>

or

 <meta itemprop="keywords" content="Game Adult"/>

我不确定在关键字包含多个单词的情况下应该做什么,因为规范中没有任何内容说明关键字应如何在文本(我假设由空格和/或逗号等标点符号组成)。

@Lawrence Woodman:您能否指出您在规范中读到的地方,即允许同一属性拥有多个 itemprop 元素?

My reading of the specification leads me to the conclusion that you can have just one itemprop attribute per property.

In other words, i don't think that creating an itemprop element for each keyword will create a correct microdata syntax.

I would put each keyword in a space-separated list, and use a single itemprop:

  <span itemprop="keywords">
  <a href="/tags/game/">Game</a>,
  <a href="/tags/adult/">Adult</a>
  </span>

or

 <meta itemprop="keywords" content="Game Adult"/>

i am not sure what should be done in case a keyword contains multiple words, since there is nothing in the specification that says how keywords should be separated in the text (i assume by spaces and.or punctuation like comma).

@Lawrence Woodman : could you indicate where you read, in the specification, that it is allowed to have multiple itemprop elements for the same property?

空‖城人不在 2024-12-21 06:32:22

通过阅读文档,我想说您可以使用元标记来解析隐藏或格式错误的内容。这就是下面代码中 priceCurrencydatePublished 的情况,取自 schema .org 文档

<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  Price: <span itemprop="price">$6.99</span>
  <meta itemprop="priceCurrency" content="USD" />
  <link itemprop="availability" href="http://schema.org/InStock">In Stock
</div>

Product details
<span itemprop="numberOfPages">224</span> pages
Publisher: <span itemprop="publisher">Little, Brown, and Company</span> - 
<meta itemprop="datePublished" content="1991-05-01">May 1, 1991
Language: <span itemprop="inLanguage">English</span>
ISBN-10: <span itemprop="isbn">0316769487</span>

假设我是对的,我已将代码更改为以下内容。

<div itemscope itemtype="http://schema.org/CreativeWork">
  <!-- way too many content -->
  <h5>Keywords</h5>
  <meta itemprop="keywords" content="Rio de Janeiro, Brazil">
  <a href="/tags/rio/" rel="nofollow">Rio de Janeiro</a>
  <a href="/tags/brazil/" rel="nofollow">Brazil</a>
</div>

我将在几天内部署它,很抱歉我现在无法判断它是否有效。

更新:部署代码后,它就像一个魅力。您可以通过 Google 数据测试工具,并与 真实产品

By reading the docs, I'd say you can use meta tags to parse content which is whether hidden or in a bad format. That's the case of priceCurrency and datePublished in the code bellow, taken from schema.org documentation.

<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  Price: <span itemprop="price">$6.99</span>
  <meta itemprop="priceCurrency" content="USD" />
  <link itemprop="availability" href="http://schema.org/InStock">In Stock
</div>

Product details
<span itemprop="numberOfPages">224</span> pages
Publisher: <span itemprop="publisher">Little, Brown, and Company</span> - 
<meta itemprop="datePublished" content="1991-05-01">May 1, 1991
Language: <span itemprop="inLanguage">English</span>
ISBN-10: <span itemprop="isbn">0316769487</span>

Assuming I am right, I've changed my code to the following.

<div itemscope itemtype="http://schema.org/CreativeWork">
  <!-- way too many content -->
  <h5>Keywords</h5>
  <meta itemprop="keywords" content="Rio de Janeiro, Brazil">
  <a href="/tags/rio/" rel="nofollow">Rio de Janeiro</a>
  <a href="/tags/brazil/" rel="nofollow">Brazil</a>
</div>

I'll deploy it in a few days, so sorry I can't tell if it works right now.

UPDATE: After deploying the code, it works like a charm. You can see the results through Google Data Testing Tool and compare to the rich snippets used on the real product.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文