Html schema.org SiteNavigationElement 的正确用法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12491102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the correct use of schema.org SiteNavigationElement?
提问by Giel Berkers
In SEO terms...
在搜索引擎优化方面...
Is it best to put the scheme on the parent containing all the links?
最好将方案放在包含所有链接的父级上吗?
<nav itemscope="itemscope" itemtype="http://www.schema.org/SiteNavigationElement">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</nav>
...or should each link be considered as it's own element?
...或者每个链接都应该被视为它自己的元素?
<nav>
<span itemscope="itemscope" itemtype="http://www.schema.org/SiteNavigationElement">
<a itemprop="url" href="#">
<span itemprop="name">Link 1</span>
</a>
</span>
<span itemscope="itemscope" itemtype="http://www.schema.org/SiteNavigationElement">
<a itemprop="url" href="#">
<span itemprop="name">Link 2</span>
</a>
</span>
<span itemscope="itemscope" itemtype="http://www.schema.org/SiteNavigationElement">
<a itemprop="url" href="#">
<span itemprop="name">Link 3</span>
</a>
</span>
</nav>
回答by unor
If SiteNavigationElement
is meant for the whole navigation (i.e., a navigation link list), your first example is correct.
如果SiteNavigationElement
用于整个导航(即导航链接列表),则您的第一个示例是正确的。
If SiteNavigationElement
is meant for a single navigation entry (i.e., a link in the navigation link list), your second example is correct.
如果SiteNavigationElement
用于单个导航条目(即导航链接列表中的链接),则您的第二个示例是正确的。
I think Schema.org doesn't unambiguously define which variant is meant, as they only say:
我认为 Schema.org 并没有明确定义哪个变体是什么意思,因为他们只是说:
A navigation element of the page.
页面的导航元素。
However, the parent type WebPageElement
is defined as:
但是,父类型WebPageElement
定义为:
A web page element, like a table or an image
网页元素,如表格或图像
Also, all the other child types (like Table
or WPFooter
) seem to be used for the whole thing, and not specific parts of the thing.
此外,所有其他子类型(如Table
或WPFooter
)似乎用于整个事物,而不是事物的特定部分。
So this seems to suggest that the whole navigation should be marked up, and not each single link:
所以这似乎表明应该标记整个导航,而不是每个链接:
<nav itemscope itemtype="http://schema.org/SiteNavigationElement">
<ul>
<li><a href="/link-1">Link 1</a></li> <!-- don't use the 'url' or 'name' property here! -->
<li><a href="/link-2">Link 2</a></li>
</ul>
</nav>
In this case, all the properties belong to the whole navigation, so that means the url
property would specify a URL for this navigation (and notthe URLs of the links in this navigation!).
在这种情况下,所有属性都属于整个导航,因此这意味着该url
属性将为该导航指定一个 URL(而不是该导航中链接的 URL!)。
回答by John R Perry
According to Search Engine Land, it's supposed to look like this:
根据Search Engine Land,它应该是这样的:
<ul itemscope itemtype="http://www.schema.org/SiteNavigationElement">
<li itemprop="name">
<a itemprop="url" href="#">Link 1</a>
</li>
<li itemprop="name">
<a itemprop="url" href="#">Link 2</a>
</li>
<li itemprop="name">
<a itemprop="url" href="#">Travel Resources</a>
</li>
</ul>
回答by Stephan Weinhold
First answer is correct but I'd mix both for (HTML5-)semantic:
第一个答案是正确的,但我将两者混合用于(HTML5-)语义:
<nav itemscope itemtype="http://schema.org/SiteNavigationElement">
<ul>
<li>
<a itemprop="url" href="http://example.com/">
<span itemprop="name">Link 1</span>
</a>
</li>
</ul>
</nav>
回答by davidcondrey
<nav role="navigation">
<ul role="menubar" aria-activedescendant="">
<li role="presentation" itemscope itemtype="https://schema.org/SiteNavigationElement">
<a href="" role="menuitem" tabindex="-1" itemprop="url">
<span itemprop="name">Link 1</span>
</a>
</li>
</ul>
</nav>
回答by ashrafnezhad
schema.org/SiteNavigationElementextends WebPageElement and can be used to mark-up links, which would often make good contextual links. You can use this schema for your page menu.
schema.org/SiteNavigationElement扩展了 WebPageElement,可用于标记链接,这通常会形成良好的上下文链接。您可以将此架构用于页面菜单。
<nav role="navigation" itemscope itemtype="http://schema.org/SiteNavigationElement">
<ul>
<li>
<a href="https://yoursite.com/" title="Link to Home" itemprop="url">
<span itemprop="name">Home</span>
</a>
</li>
<li>
<a href="https://yoursite.com/sample-page" title="Link to sample page" itemprop="url">
<span itemprop="name">sample page</span>
</a>
</li>
</ul>
回答by Josh Habdas
Consider the following code snippet adapted from the page source of habd.as:
考虑以下改编自habd.as页面源代码的代码片段:
<nav itemscope itemtype="https://schema.org/SiteNavigationElement">
<meta itemprop="name" content="Main Menu">
<a itemprop="url" class="active" href="/">habd.as</a>
<a itemprop="url" href="/code/">Code</a>
<a itemprop="url" href="/post/">Posts</a>
<a itemprop="url" href="/site/">Sites</a>
<a itemprop="url" href="/talk/">Talks</a>
</nav>
<nav itemscope itemtype="https://schema.org/SiteNavigationElement">
<meta itemprop="name" content="Utility Menu">
<a itemprop="url" href="/about/">About</a>
<a itemprop="url" href="/contact/">Contact</a>
</nav>
When there are multiple navigations as shown above, use of SiteNavigationElement
to groupnavigation items affords the use of name
such that the grouping itself may be labeled. Labels for individual items within the groups can be obtained using the content of the links themselves.
当有如上所示的多个导航时,使用 对导航项SiteNavigationElement
进行分组提供了使用,name
以便可以标记分组本身。可以使用链接本身的内容获得组内单个项目的标签。
Therefore, your first example is more correct despite assertions to the contrary.
因此,尽管有相反的断言,但您的第一个示例更正确。
回答by David Barratt
I think the most elegent solution would be to use the hasPartproperty.
<nav itemscope="itemscope" itemtype="http://www.schema.org/SiteNavigationElement">
<a itemprop="hasPart" href="/link1.html">Link 1</a>
<a itemprop="hasPart" href="/link2.html">Link 2</a>
<a itemprop="hasPart" href="/link3.html">Link 3</a>
</nav>
Using Google's Structure Data Testing Toolinforms that these links are part of the SiteNavigationElement and that Google should follow the links to those items:
使用 Google 的结构数据测试工具会告知这些链接是 SiteNavigationElement 的一部分,并且 Google 应遵循这些项目的链接:
回答by Роман Арсеньев
Having considered all the above, I came to the following conclusion:
考虑了以上所有因素,我得出以下结论:
<nav itemscope itemtype="http://schema.org/SiteNavigationElement">
<ul>
<li itemprop="hasPart">
<a href="/" itemprop="url"><span itemprop="name">Home</span></a>
</li>
</nav>
Thus, each <li>
is part of the SiteNavigationElement
that has the url
and name
. I think this is the best option.
因此,每个<li>
都是SiteNavigationElement
具有url
和 的 的一部分name
。我认为这是最好的选择。
But do search engines need such redundant markup? They already know that href
in <a href="">
is the url
, and inside the tag <a>name</a>
is the name
. What do you think about it?
但是搜索引擎需要这样的冗余标记吗?他们已经知道href
in<a href="">
是url
,标签里面<a>name</a>
是name
。你怎么看待这件事?
回答by Mathieu VIALES
OP's original question contained a good example of code. none of the answers do though ...
OP 的原始问题包含一个很好的代码示例。虽然没有一个答案...
It seems everyone threw in a somewhat random answer ... You can test your schema microdata code using the following official google toolsearch.google.com/structured-data/testing-tool.
似乎每个人都给出了一个有点随机的答案......您可以使用以下官方谷歌工具search.google.com/structured-data/testing-tool测试您的架构微数据代码。
If you run the proposed answers in this tool you will notice that none give you the expected result: a list of SiteNavigationElement
with a name & url
如果您在此工具中运行建议的答案,您会注意到没有一个给您预期的结果:SiteNavigationElement
带有名称和网址的列表
Some might argue that a whole menu might be considered a "navigation element" but I think it makes more sense for this denomination to designate a single navigation link. Plus if we use the SiteNavigationElement
as a marker for the whole menu we have no way of associating names with URLs in the html.
有些人可能会争辩说,整个菜单可能被认为是一个“导航元素”,但我认为这个名称指定单个导航链接更有意义。另外,如果我们将SiteNavigationElement
用作整个菜单的标记,我们将无法将名称与 html 中的 URL 相关联。
To achieve this, you need to have each link be encapsulated by an itemscope
property and they all need to have their own name
and url
itemprop
(these are singleton as mentioned by @David Harkness, so they have to appear only once per itemprop
)
要实现这一点,您需要让每个链接都由一个itemscope
属性封装,并且它们都需要有自己的name
和url
itemprop
(这些是@David Harkness 提到的单例,因此它们每个只出现一次itemprop
)
<nav>
<ul>
<li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a itemprop="url" href="http://example.com/link-1">
<span itemprop="name">Link 1</span>
</a>
</li>
<li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a itemprop="url" href="http://example.com/link-2">
<span itemprop="name">Link 2</span>
</a>
</li>
</ul>
</nav>
The code above will yeld two different navigation elements, each with a name and an URL.
上面的代码将生成两个不同的导航元素,每个元素都有一个名称和一个 URL。
Note: the itemprop="url"
attribute uses the anchor's href
attribute as value
注意:itemprop="url"
属性使用锚的href
属性作为值