因为我使用的是asp.net MVC,所以视图在我的体内使用@RenderBody()呈现。
我的问题是:我是否正确地使用了schema.org微数据?
在我的示例中,我有一个html,即WebSite,它在WebSite项目范围的标题中有一些元数据。接下来,我将mainEntityOfPage设置为WebPage并添加页眉、页脚。一些将附加在@RenderBody()中的页面有自己的作用域(例如ContactPage),而另一些页面只有一些产品或位置的项目范围的数据。
这是使用微数据的正确方式吗?
简化_Layout.cshtml
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/WebSite">
<head prefix="og: http://ogp.me/ns#">
<meta property="og:title" content="test">
<meta itemprop="about" content="test">
</head>
<body itemprop="mainEntityOfPage" itemscope itemtype="http://schema.org/WebPage">
<div class="myheader" itemscope itemtype="http://schema.org/WPHeader">
<div class="...">
<nav class="navbar navbar-default navbarwrapper" itemscope itemtype="http://schema.org/SiteNavigationElement">
@*...*@
</div>
</div>
</div>
@RenderBody()
<div>
@* some other stuff*@
</div>
<div class="myfooter" itemscope itemtype="http://schema.org/WPFooter">
@*...*@
</div>
</body>
简化的Index.cshtml (Home),它显示在@RenderBody()中,因此显示在没有任何其他项目作用域的WebPage项目范围中:
<div class="...">
@* content *@
</div>
简化的Contact.cshtml (Home),它显示在@RenderBody()中,因此显示在WebPage项目范围和其他作用域中:
<div class="banner">
@* banner stuff *@
</div>
<div class="myMiddleContent" itemscope itemtype="http://schema.org/ContactPage">
<div class="container">
<div class="row">
@*...*@
<div class="col-md-6" itemscope itemtype="http://schema.org/Place">
@*...*@
</div>
</div>
</div>
</div>
更新:
这就是我现在拥有的:
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/WebSite">
<head prefix="og: http://ogp.me/ns#">
<meta property="og:title" content="test">
<meta itemprop="about" content="test">
<meta itemprop="headline" content="my fancy pancy site">
<meta itemprop="cool, things here">
</head>
<body itemprop="mainEntity" itemscope itemtype="http://schema.org/ContactPage"> @* or /WebPage *@
<div class="myheader" itemprop="hasPart" itemscope itemtype="http://schema.org/WPHeader">
<div class="...">
<nav class="navbar navbar-default navbarwrapper" itemprop="hasPart" itemscope itemtype="http://schema.org/SiteNavigationElement">
@*...*@
</div>
</div>
</div>
@* injected via @RenderBody() *@
<div class="banner">
@* banner stuff *@
</div>
<div class="myMiddleContent">
<div class="container">
<div class="row">
@* list of products...*@
<div class="col-md-6" itemscope itemtype="http://schema.org/Product">
@*product x...*@
</div>
<div class="col-md-6" itemscope itemtype="http://schema.org/Product">
@* product y...*@
</div>
</div>
</div>
</div>
<div itemprop="contentLocation" itemscope itemtype="http://schema.org/Museum">
<link itemprop="additionalType" href="http://schema.org/TouristAttraction">
<meta itemprop="name" content="Foo bar">
<meta itemprop="sameAs" content="http://www.facebook.com/FooBar">
<div itemprop="openingHoursSpecification" itemscope itemtype="http://schema.org/OpeningHoursSpecification">
@*...*@
</div>
</div>
@* end of injected via @RenderBody() *@
<div>
@* some other stuff*@
</div>
<div class="myfooter" itemprop="hasPart" itemscope itemtype="http://schema.org/WPFooter">
@*...*@
</div>
@*website/webpage creator / author / etc... *@
<div itemprop="creator" itemscope itemtype="http://schema.org/LocalBusiness">
<meta itemprop="name" content="...">
@*...*@
</div>
<div itemprop="copyrightHolder" itemscope itemtype="http://schema.org/LocalBusiness">
@*...*@
</div>
</body>
</html>
发布于 2016-03-19 16:26:48
由于Index.cshtml中没有模式标记,所以当插入到_Layout.cshtml中时,我将讨论Contact.cshtml。这适用于Index.cshtml,除非引用Contact.cshtml中的内容。
模式标记的读取方式如下:
标记存在许多问题,包括但不限于页面上的项缺乏层次结构和不正确的schema.org使用。我将在下面逐行讨论您的代码:
此标记通知此页上的HTML是网站。这很好,但可能不是你想要的。对于模式标记来说,术语是很重要的--也许这应该是一个WebPage?我过会儿再谈这个。
在这里,您说明WebSite是mainEntityOfPage: WebPage。这几乎肯定不是你想要的。为了澄清,您说的是WebPage (这个单页) mainEntity (这个页面的主要内容)是WebSite (整个站点)。我鼓励您检查schema.org/mainEntityOfPage是否符合此属性的规范。下面是我要做的事情:
<!DOCTYPE html>
<html>
<head prefix="og: http://ogp.me/ns#">
<meta property="og:title" content="test">
<meta itemprop="about" content="test">
</head>
<body itemscope itemtype="http://schema.org/WebPage">
删除项目项目将删除从WebPage到WebSite的链接,并且由于您没有使用任何WebSite属性,所以可以删除WebSite模式。
这是两个完全不同的模式。它们既不相互关联,也不与WebPage模式相关联。在这两种情况下,您都缺少了itemprop属性。它们都应该包括itemprop="hasPart"
,以定义以下层次结构:
这有点困难,因为ContactPage是一个WebPage,但是您已经在WebPage的范围内了,它本身并不是一个不同的页面。通常,您会将这两者与itemprop="mainEntity"
链接,但项目类型是WebPage,因此这是不正确的。mainContentOfPage用于WebPageElement,但您仍然定义了整个页面。
这就是应该将WebPage模式替换为ContactPage的地方,但据我所知,您的“插入”@RenderBody()
并不能适应这种情况。我想,如果不能根据要插入的页面更改mainEntity模式(WebPage仍然是Index.cshtml最合适的模式),那么最好的方法就是使用WebPage。如果能够在插入联系人页时更改布局页,则应将WebPage更改为ContactPage,而不是使用mainEntity。由于后面讨论的联系人页面中的模式适用于ContactPage模式,因此以后不需要进行任何进一步的更改。
假设您在插入联系人页时无法更改布局页,到目前为止的架构如下:
- mainEntity: ContactPage
到目前为止,这个地方与任何东西都是完全不同的--再一次,这个模式中缺少了一个项目。使用contentLocation (或者定义一个组织/etc来包含这个位置)。然后,你就会得到…
- mainEntity: ContactPage
- contentLocation: Place
@\*...\*@ </div> </div> </div> </div> <div> @\* some other stuff\*@ </div> <div class="myfooter" itemscope itemtype="http://schema.org/WPFooter">
和WPHeader一样,WPFooter也缺少了hasPart。完成的模式如下所示:
- mainEntity: ContactPage
- contentLocation: Place
- hasPart: WPFooter
如果您能够在插入联系人页时更改布局页,架构如下所示:
- contentLocation: Place
- hasPart: WPFooter
修正后的代码(包括修复<nav></div>
)如下:
<!DOCTYPE html>
<html>
<head prefix="og: http://ogp.me/ns#">
<meta property="og:title" content="test">
<meta itemprop="about" content="test">
</head>
<body itemscope itemtype="http://schema.org/WebPage">
<div class="myheader" itemprop="hasPart" itemscope itemtype="http://schema.org/WPHeader">
<div class="...">
<nav class="navbar navbar-default navbarwrapper" itemprop="hasPart" itemscope itemtype="http://schema.org/SiteNavigationElement">
@*...*@
</nav>
</div>
</div>
@RenderBody()
<div>
@* some other stuff*@
</div>
<div class="myfooter" itemprop="hasPart" itemscope itemtype="http://schema.org/WPFooter">
@*...*@
</div>
</body>
<div class="banner">
@* banner stuff *@
</div>
<div class="myMiddleContent" itemprop="hasPart" itemscope itemtype="http://schema.org/ContactPage">
<div class="container">
<div class="row">
@*...*@
<div class="col-md-6" itemprop="contentLocation" itemscope itemtype="http://schema.org/Place">
@*...*@
</div>
</div>
</div>
</div>
Google结构化数据测试工具不能正确地显示这一点,因为有些项目缺少内容。
https://stackoverflow.com/questions/36081670
复制相似问题