在Drupal 7中为面包屑SEO添加微数据或schema.org [英] Adding microdata or schema.org for breadcrumb SEO in Drupal 7

查看:229
本文介绍了在Drupal 7中为面包屑SEO添加微数据或schema.org的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前对微数据和schema.org感到困惑。 微数据和schema.org是否相同?我阅读了 Google Microsoft 文档,但是这并没有帮助我得到这两个名字之间的区别。



到目前为止,我了解到我已经生成了这个HTML代码:

 < span itemscope itemtype =http://data-vocabulary.org/Breadcrumb> 
< a href =/itemprop =url>< span itemprop =title>我的页面< / span>< / a>
< / span>
< span itemscope itemtype =http://data-vocabulary.org/Breadcrumb>
< a href =/ cat1itemprop =url>< span itemprop =title>类别1< / span>< / a>
< / span>
< span itemscope itemtype =http://data-vocabulary.org/Breadcrumb>
< a href =/ cat1 / contentitemprop =url>< span itemprop =title> Content< / span>< / a>
< / span>

在我看来,太多的开销,但如果搜索结果看起来不错,可以。 是否可以减少html代码的数量?



另外如果我不需要搜索引擎如何检测两个不同的路线?



我的下一个问题是我要将这种格式应用到drupal breadcrumps。我在网页上找到了这个修复程序,我试图将这个修改包含在我自己的SEO模块中:

  function mymod_page_alter(& $ variables){
if(!isset($ variables ['breadcrumb'])){
$ variables ['breadcrumb'] = theme('my_microdata',array('breadcrumb'=> drupal_get_breadcrumb()));
}
}
函数mymod_theme($ existing,$ type,$ theme,$ path){
return array(
'my_microdata'=> array b $ b'variables'=> array('breadcrumb'=> array()),
),
);
}
函数mymod_menu_breadcrumb_alter(& $ active_trail,$ item){
foreach($ active_trail as $ id => $ active_trail_item){
$ active_trail [$ id] [ 'localized_options'] [ '属性'] [ 'itemprop'] [] = URL;
}
}
function theme_my_microdata($ variables){
$ breadcrumb = $ variables ['breadcrumb'];
print_r(debug_backtrace());
$ output =* + * + * + * + *;
if(!empty($ breadcrumb)){
//提供导航标题,为
// screen-reader用户提供面包屑链接的上下文。使标题看不见.element-invisible。
$ output ='< h2 class =element-invisible>'。 t('你在这里')。 < / 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 有关吗?我知道这个输出将会是垃圾,但是我看不到结果。



如果我猜这个输出是由 theme.inc 行1682ff theme_breadcrumb(...)而不是我的代码。



如果有人可以帮助我,如果你不知道我的问题的所有答案!

解决方案

微数据和schema.org是一样的?



不,他们不是!



Microdata是一个 WHATWG html规范。计算机读取文档的内容更为容易。



Schema.org是用于描述项目的词汇表。 Bing,Google和Yahoo引入了Schema.org。



http://en.wikipedia.org/wiki/Microdata_(HTML)



http://www.w3.org/TR/html5/microdata.html



http://schema.org/



是否可以减少html代码的数量?



查看schema.org的示例代码以获取标记的WebPage项目: http://schema.org/WebPage


 < body itemscope itemtype =http://schema.org/以下网页> 
...
< div itemprop =breadcrumb>
< a href =category / books.html>图书< / a> >
< a href =category / books-literature.html> Literature&小说< / A> >
< a href =category / books-classics> Classics< / a>
< / div>


搜索引擎如何检测两个不同的路径



如果您使用schema.org中的上述示例,则可以标记一个跟踪,而不是单个链接。如果标记两条路径,那么它们将被识别为两个。 <或>至少应该是



为什么代码不起作用?



我认为这个问题应该与这个帖子分开,并以另一个问题来问。我不熟悉drupal,有些人可以回答有关微数据的问题,甚至不了解PHP。


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.

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>

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?

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";
}

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.

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!

解决方案

Is microdata and schema.org the same?

No they are not!

Microdata is a WHATWG html specification. It's supose to make it easier for computers to read the content of the document.

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

http://schema.org/

Is it possible to reduce the count of html code?

Have a look at the exemple code at schema.org for the markup of a WebPage item: http://schema.org/WebPage

<body itemscope itemtype="http://schema.org/WebPage">
...
<div itemprop="breadcrumb">
  <a href="category/books.html">Books</a> >
  <a href="category/books-literature.html">Literature & Fiction</a> >
  <a href="category/books-classics">Classics</a>
</div>

How does the search engines detect two different trails

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)

Why does that code not work?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆