我目前对微数据和 schema.org 有点困惑。 microdata 和 schema.org 一样吗? 我读了 Google和 Microsoft文档,但这并没有帮助我区分这两个名称。
到目前为止,我理解了这一点,我已经生成了这段 HTML 代码:
<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代码的数量?
此外,如果我不需要,搜索引擎如何检测两条不同的路径?
我的下一个问题是我想将这种格式应用于 drupal 面包屑。我在网上找到this fix我试图像这样将其包含到我自己的 SEO 模块中:
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
相关吗?我知道此输出将是垃圾,但我看不到结果。
如果我猜对了,theme.inc 行 1682ff theme_breadcrumb(...)
而不是我的代码创建的输出。
如果有人能帮助我就好了,即使你不知道我的问题的所有答案!
最佳答案
microdata 和 schema.org 一样吗?
不,他们不是!
微数据是一个WHATWG html规范。它旨在使计算机更容易阅读文档的内容。
Schema.org 是用于描述项目的词汇表。 Schema.org 由 Bing、Google 和 Yahoo 引入。
http://en.wikipedia.org/wiki/Microdata_(HTML)
http://www.w3.org/TR/html5/microdata.html
是否可以减少html代码的数量?
查看 schema.org 上网页项目标记的示例代码: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>
搜索引擎如何检测两条不同的路径
如果您使用来自 schema.org 的上述示例,您标记的是路径而不是单个链接。如果您标记两条路径,它们都将被识别为两个单独的路径。 (或者至少应该是)
为什么该代码不起作用?
我认为这个问题应该从这个帖子中分离出来,在不同的帖子中提出。我不熟悉 drupal,一些可以回答有关微数据问题的人甚至不知道 PHP。
关于drupal - 在 Drupal 7 中为面包屑搜索引擎优化添加微数据或 schema.org,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10371410/