问题
I tried a simple example, but the SiteNavigationElement
is not working when I test it using the Google Structured Data Testing Tool. It gives the error:
SiteNavigationElement
is not a known valid target type for theadditionalType
property.
The Microdata:
<div itemscope itemtype="http://schema.org/WebPageElement">
<link itemprop="additionalType" href="http://schema.org/ItemList" />
<meta itemprop="name" content="navigation_menu" />
<ul>
<li itemprop="additionalType" itemscope itemtype="http://www.schema.org/SiteNavigationElement">
<span itemprop="itemListElement">
<a href="http://www.example.com/link_1" itemprop="url">
<span itemprop="name">Link 1</span>
</a>
</span>
</li>
<li itemprop="additionalType" itemscope itemtype="http://www.schema.org/SiteNavigationElement">
<span itemprop="itemListElement">
<a href="http://www.example.com/link_2" itemprop="url">
<span itemprop="name">Link 2</span>
</a>
</span>
</li>
</ul>
</div>
回答1:
The additionalType
property should not be used to create another item (which you are doing with itemscope
+itemtype
). Its job is to provide the URI of additional types, so the URI itself is the value here.
It seems that you want to mark up each link in your navigation. This is not possible with SiteNavigationElement
(it can only be used to mark up the whole navigation, so it’s typically useless).
It would be possible with ItemList
, and you could provide SiteNavigationElement
as additionalType
(but I wouldn’t expect any consumer to make use of this):
<div itemscope itemtype="http://schema.org/ItemList">
<link itemprop="additionalType" href="http://schema.org/SiteNavigationElement" />
<ul>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/WebPage">
<a href="/link-1" itemprop="url"><span itemprop="name">Link 1</span></a>
</li>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/WebPage">
<a href="/link-2" itemprop="url"><span itemprop="name">Link 2</span></a>
</li>
</ul>
</div>
Or as an actual MTE (without additionalType
):
<div itemscope itemtype="http://schema.org/ItemList http://schema.org/SiteNavigationElement">
<ul>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/WebPage">
<a href="/link-1" itemprop="url"><span itemprop="name">Link 1</span></a>
</li>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/WebPage">
<a href="/link-2" itemprop="url"><span itemprop="name">Link 2</span></a>
</li>
</ul>
</div>
回答2:
Same as the MTE example above by @unor, except in JSON-LD. (If your list has id's it makes sense to use them.)
<script type="application/ld+json">
{
"@context":"http://schema.org",
"@type":["ItemList", "SiteNavigationElement"],
"@id": "https://example.com/#nav",
"url":"https://example.com/#nav",
"itemListElement":[
{
"@type":"WebPage",
"position":1,
"name": "home",
"@id": "https://example.com/#home",
"url":"https://example.com/home.html"
},
{
"@type":"WebPage",
"position":2,
"name": "Core Solutions",
"@id": "https://example.com/#core",
"url":"https://example.com/core.html"
}
]
}
</script>
来源:https://stackoverflow.com/questions/45375187/error-in-sdtt-sitenavigationelement-is-not-a-known-valid-target-type-for-the-a