具有微数据的多时间元素 [英] Multiple Time Elements with Microdata

查看:115
本文介绍了具有微数据的多时间元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表示我的业务开放时间的定义列表:

I have a definition list representing my business' opening hours:

<dl>
  <dt>Monday - Friday</dt>
  <dd>8:30am to 5:30pm</dd>
  <dt>Saturday - Sunday</dt>
  <dd>9:00am to 5:00pm</dd>
  <dt>Holidays</dt>
  <dd>Closed</dd>
</dl>

这似乎是一个很好的结构化的方式来安排这个内容。但是也许我错了?

This seems like a good, structured way to arrange this content. But perhaps I am wrong?

我想知道如何使用 time 元素来表示开放时间?

I am wondering how I would use the time element to represent the opening hours?

最终,我正在看这样做:

Ultimately, I was looking at doing something like this:

<time itemprop="openingHours" datetime="Mo,Tu,We,Th,Fr 8:30-17:30">Monday - Friday, 8:30am to 5:30pm</time>

但是,在 dt 标签和 dd 的时间,我不知道标记的正确方法是什么?两个不同的时间标签似乎错误。

But with the days of the week in the dt tag and the hours in the dd's, I'm not sure what the proper approach to the markup would be? Two different time tags seems wrong.

推荐答案

使用Microdata,您是不是注释你的HTML标记。标记仅作为载体。在Microdata消费者解析了该页面之后,HTML和Microdata项目之间没有任何关系。

With Microdata, you are not "annotating" your HTML markup. The markup serves only as a carrier. After a Microdata consumer parsed the page, there is no relation between the HTML and the Microdata items anymore.

所以你实际上有两个问题:

So you have actually two questions:


  • 我应该使用哪个HTML5标记?

  • 如何使用这个标记来添加我想与Microdata说的内容?

HTML5问题很简单:您可以使用 time 元素,作为日期,时间,时区偏移或持续时间的所有内容。因此,您的 dl 可能如下所示:

The HTML5 question is easy: You can use the time element for everything that is a date, time, time-zone offset, or duration. So your dl could look like:

<dl>
  <dt>Monday - Friday</dt>
    <dd><time datetime="08:30">8:30am</time> to <time datetime="17:30">5:30pm</time></dd> <!-- could also use a duration string instead, or an additional time element; but probably doesn’t make much sense in this context -->
  <dt>Saturday - Sunday</dt>
    <dd><time datetime="09:00">9:00am</time> to <time datetime="17:00">5:00pm</time></dd>
  <dt>Holidays</dt>
    <dd>Closed</dd>
</dl>



Schema.org和Microdata



现在看看schema.org的 openHours 属性的定义,我们看到没有强制性的内容格式:开放时间可以指定为[...](强调我的)。

Schema.org and Microdata

Now looking at the definition of schema.org’s openingHours property, we see that there is no mandatory content format: "Opening hours can be specified as […]" (emphasis mine).

但是,他们以文档/推荐为格式的语法是无效的HTML5 time a>不能像Mo,Tu,We,Th,Fr 8:30-17:30或Mo-Su(我创建了一个问题)。

However, the syntax they document/recommend as possible format is invalid HTML5: the time element can’t have a datetime value like "Mo,Tu,We,Th,Fr 8:30-17:30" or "Mo-Su" (I created an issue).

所以如果你想使用这种记录的格式,你不应该使用时间元素。相反,您可以

So if you want to use this documented format, you should not use the time element. Instead, you could

<data itemprop="openingHours" value="Mo,Tu,We,Th,Fr 8:30-17:30">…</data>

您可以使用它来包装相应的 dt dd ,如果你愿意的话。

You could use it to wrap the content of the corresponding dt or dd, if you like.

使用 meta 元素

<meta itemprop="openingHours" content="Mo,Tu,We,Th,Fr 8:30-17:30">

您可以将其作为相应的 dt dd ,如果你愿意的话(是的, body )。

You could place it as child of the corresponding dt or dd, if you like (yes, in the body).

你可能想使用 openingHoursSpecification OpeningHoursSpecification

You might want to use openingHoursSpecificationOpeningHoursSpecification instead.

这篇关于具有微数据的多时间元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆