问题描述
如何将 mainEntityOfPage
正确添加到此站点?
在 Google 文档示例中,我看到如下内容:
<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="https://google.com/article"/>但这是一个单作者博客.它包含博客帖子.
我改成这样好不好:
<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="https://linktoarticle"/>
不确定我是否理解 mainEntityOfPage
的用法.如果有人能建议我如何处理这个特定案例/网站,我将不胜感激.不是一般的,因为每个站点可以有不同的 mainEntityOfPage
,但我需要知道和理解这个站点的正确实现.
解决方案 关于 Google 的微数据示例
Google 的微数据示例无效.如果 meta
元素具有 itemprop
属性,则需要 content
属性(详情).
我描述了如何在微数据中指定mainEntityOfPage
的不同方式,最直接的一种是创建 URL 值(而不是另一个微数据项)的 link
元素:
mainEntity
如果我们先看一下它的逆属性,就更容易理解 mainEntityOfPage
的用法, mainEntity
.
对于包含 BlogPosting
的 WebPage
,我们可以:
这意味着:有一个 WebPage
和一个 BlogPosting
,BlogPosting
是这个 WebPage 中描述的主要实体"代码>.如果涉及更多项目,例如,描述作者的 Person
,相关帖子的另外五个 BlogPosting
项目,一个 WebSite
项目提供一些元数据等.感谢 mainEntity
/mainEntityOfPage
,消费者可以了解该页面上的主要/主要项目是什么(即页面代表什么).
mainEntityOfPage
以下带有 mainEntityOfPage
的示例将产生与上面带有 mainEntity
的示例相同的结构化数据:
<div itemprop="mainEntityOfPage" itemscope itemtype="http://schema.org/WebPage">
</文章>
如您所见,BlogPosting
项的元素包含 WebPage
项的元素.这当然是相当不寻常的标记.
但是 mainEntityOfPage
属性不仅期望 (CreativeWork
) 项目作为值,它或者需要一个 URL.因此,您可以提供页面的 URL,而不是显式提供 WebPage
项:
<link itemprop="mainEntityOfPage" href="http://example.com/article-1"/></文章>
(这是 Google 所期望的,根据他们的 文章 Rich Snippet 文档.)
附注:页面与帖子的网址
许多网站不区分网页的 URL 和博客文章的 URL.对于这些网站,声明诸如
之类的内容似乎很愚蠢http://example.com/article-1(博客文章)是mainEntityOfPage"http://example.com/article-1(网页)
http://example.com/article-1(网页)有'mainEntity'http://example.com/article-1(博客文章)
但无论如何它都是有用的(例如,选择哪个项目是主要项目,因为其他项目不会有这个语句;或者对于一个空白节点;等等).
但是,有些网站确实存在差异(尤其是对于关联数据),因此它们可能会声明类似
http://example.com/article-1#this(博客文章)是mainEntityOfPage"http://example.com/article-1(网页)
http://example.com/article-1(网页)有'mainEntity'http://example.com/article-1#this(博客文章)
这里,http://example.com/article-1#this
代表博文,http://example.com/article-1
代表包含有关此帖子(或帖子本身的内容)的信息的页面.一个更清楚的例子是一个人和一个关于这个人的页面;或建筑物和有关该建筑物的页面.有关为什么要这样做的示例,请参阅我的回答.(但是,如上所述,您不必区分;您可以对两者使用相同的网址.)
Please take a look here: https://developers.google.com/structured-data/testing-tool?url=https%253A%252F%252Fglamourina.net%252Fen%252F
How can I correctly add mainEntityOfPage
to this site?
In Google documentation example I see something like this:
<div itemscope itemtype="http://schema.org/NewsArticle">
<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="https://google.com/article"/>
But this is a single author blog. And it features blogPosts.
<article itemscope itemtype="https://schema.org/BlogPosting" class="singlearticles">
Would it be good if I change it like this:
<article itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
<meta itemscope itemprop="mainEntityOfPage" itemType="https://schema.org/WebPage" itemid="https://linktoarticle"/>
Not sure if I understand well the mainEntityOfPage
usage. I would appreciate if someone can suggest how can I do to this specific case/website. Not generically, because each site can have a different mainEntityOfPage
, but I need to know and understand the right implementation for this site.
About Google’s Microdata example
Google’s Microdata example is invalid. If the meta
element has the itemprop
attribute, the content
attribute is required (details).
I described different ways how to specify mainEntityOfPage
in Microdata, the most straigtforward one being a link
element that creates a URL value (instead of another Microdata item):
<link itemprop="mainEntityOfPage" href="http://example.com/article-1" />
mainEntity
It’s easier to understand the use of mainEntityOfPage
if we first look its inverse property, mainEntity
.
For a WebPage
that contains a BlogPosting
, we could have:
<body itemscope itemtype="http://schema.org/WebPage">
<article itemprop="mainEntity" itemscope itemtype="http://schema.org/BlogPosting">
</article>
</body>
This means: There’s a WebPage
and a BlogPosting
, and the BlogPosting
is the "primary entity" described in this WebPage
. To denote this especially makes sense if there are more items involved, e.g., a Person
describing the author, five more BlogPosting
items for related posts, a WebSite
item giving some metadata, etc. Thanks to mainEntity
/mainEntityOfPage
, consumers can learn what the primary/main item on that page is (i.e., what the page stands for).
mainEntityOfPage
The following example with mainEntityOfPage
would result in equivalent structured data like the example with mainEntity
from above:
<article itemscope itemtype="http://schema.org/BlogPosting">
<div itemprop="mainEntityOfPage" itemscope itemtype="http://schema.org/WebPage">
</div>
</article>
As you can see, the element for the BlogPosting
item contains the element for the WebPage
item. This is of course rather unusual markup.
But the mainEntityOfPage
property does not only expect an (CreativeWork
) item as value, it alternatively expects a URL. So instead of providing a WebPage
item explicitly, you can provide the URL of the page instead:
<article itemscope itemtype="http://schema.org/BlogPosting">
<link itemprop="mainEntityOfPage" href="http://example.com/article-1" />
</article>
(This is what Google expects, according to their documentation for the Articles Rich Snippet.)
Excursus: URL of page vs. post
Many sites don’t differentiate between the URL for the web page and the URL for the blog post. For these sites it might seem silly to state something like
http://example.com/article-1 (the blog post)
is the 'mainEntityOfPage'
http://example.com/article-1 (the web page)
http://example.com/article-1 (the web page)
has 'mainEntity'
http://example.com/article-1 (the blog post)
But it can be useful anyway (e.g., for choosing which item is the primary one, because the other items won’t have this statement; or for a blank node; etc.).
However, some sites do differentiate (especially for Linked Data), so they might state something like
http://example.com/article-1#this (the blog post)
is the 'mainEntityOfPage'
http://example.com/article-1 (the web page)
http://example.com/article-1 (the web page)
has 'mainEntity'
http://example.com/article-1#this (the blog post)
Here, http://example.com/article-1#this
represents the blog posting, and http://example.com/article-1
represents the page with information about this posting (or the content of the posting itself). A clearer example would be a person and a page about this person; or a building and a page about this building. See my answer for an example why you might want to do this. (But, as explained above, you don’t have to differentiate; you can use the same URL for both.)
这篇关于如何实现“mainEntityOfPage"到这个特定的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!