在 Drupal 7 中为面包屑 SEO 添加微数据或 schema.org [英] Adding microdata or schema.org for breadcrumb SEO in Drupal 7
问题描述
我目前对微数据和 schema.org 有点困惑.微数据和 schema.org 是否相同?我阅读了Google 和 Microsoft 文档,但这并没有帮助我了解这两个名称之间的区别.
I'm currently a little confused about microdata and schema.org. Is microdata and schema.org the same? I read the Google and Microsoft documentation, but that didn't helped me to get the difference between this two names.
到目前为止,我已经理解了这一点,我已经生成了这个 HTML 代码:
So far I understood this I have produced this HTML code:
<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="/" itemprop="url"><span itemprop="title">My Page</span></a>
</span>
<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="/cat1" itemprop="url"><span itemprop="title">Category 1</span></a>
</span>
<span itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="/cat1/content" itemprop="url"><span itemprop="title">Content</span></a>
</span>
在我看来,开销太大,但如果搜索结果看起来不错就可以了.是否可以减少html代码的数量?
In my opinion too much overhead but okay if the search results look nice. Is it possible to reduce the count of html code?
另外,如果我不需要那个搜索引擎如何检测两条不同的路径?
Also if I don't need that how does the search engines detect two different trails?
我的下一个问题是我想将此格式应用于 drupal 面包屑.我在网上找到了这个修复,我试图将其包含到我自己的 SEO 模块中,如下所示:
My next problem is that I want to apply this format to the drupal breadcrumps. I found on the web this fix which I tried to include to my own SEO module like this:
function mymod_page_alter(&$variables) {
if (!isset($variables['breadcrumb'])) {
$variables['breadcrumb'] = theme('my_microdata', array('breadcrumb' => drupal_get_breadcrumb()));
}
}
function mymod_theme($existing, $type, $theme, $path) {
return array(
'my_microdata' => array(
'variables' => array('breadcrumb' =>array()),
),
);
}
function mymod_menu_breadcrumb_alter(&$active_trail, $item){
foreach($active_trail as $id=>$active_trail_item){
$active_trail[$id]['localized_options']['attributes']['itemprop'][]="url";
}
}
function theme_my_microdata($variables){
$breadcrumb=$variables['breadcrumb'];
print_r(debug_backtrace());
$output="*+*+*+*+*";
if (!empty($breadcrumb)) {
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
$output .= '<div class="breadcrumb">';
$separator="";
foreach($breadcrumb as $breadcrumb_item){
$output.='<span typeof="datav:Breadcrumb">'.$separator.$breadcrumb_item."</span>";
$separator="»";
}
$output .='</div>';
}
return $output."xXxXxXx";
}
到目前为止,我检查了所有这些代码都已执行.但是这个主题不适用于我的页面.为什么该代码不起作用?这可能与 breadcrumb
模块有关吗?我知道这个输出会很垃圾,但我看不到结果.
So far I checked that all this code is executed. But this theming is not applied on my page. Why does that code not work? Could this been related with the module breadcrumb
? I know that this output will be garbage but I cannot see the result.
如果我猜对了,输出是由 theme.inc 行 1682ff theme_breadcrumb(...)
而不是我的代码创建的.
If I guess right than is the output created by theme.inc line 1682ff theme_breadcrumb(...)
instead of my code.
如果有人能帮助我就好了,如果你不知道我问题的所有答案!
It would be nice if somebody could help me, also if you don’t know all answers of my questions!
推荐答案
microdata 和 schema.org 一样吗?
不,他们不是!
微数据是一个 WHATWG html 规范.应该是为了让电脑更容易阅读文档的内容.
Microdata is a WHATWG html specification. It's supose to make it easier for computers to read the content of the document.
Schema.org 是用于描述项目的词汇表.Schema.org 由 Bing、Google 和 Yahoo 推出.
Schema.org is a vocabulary that is used to describe an item. Schema.org is introduced by Bing, Google and Yahoo.
http://en.wikipedia.org/wiki/Microdata_(HTML)一个>
http://www.w3.org/TR/html5/microdata.html
是否可以减少html代码的数量?
查看 schema.org 中用于标记网页项目的示例代码:http://schema.org/网页
Have a look at the exemple code at schema.org for the markup of a WebPage item: http://schema.org/WebPage
搜索引擎如何检测两条不同的踪迹
如果您使用来自 schema.org 的上述示例,则您标记的是一条路径而不是单个链接.如果您标记两条路径,它们都将被识别为两个单独的路径.(或者至少应该是)
If you use the above example from schema.org instead you mark up a trail instead of individual links. If you mark up two trails they will both be recognized as two individual ones. (Or at least should be)
为什么该代码不起作用?
我认为这个问题应该与这篇文章分开,并在另一个帖子中提出.我不熟悉 drupal,一些可以回答有关微数据问题的人甚至不知道 PHP.
I think this question should be separated from this post and asked in a different one. I'm not familiar with drupal and some of the people that can answer questions regarding microdata don't even know PHP.
这篇关于在 Drupal 7 中为面包屑 SEO 添加微数据或 schema.org的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!