2012-04-29 70 views
5

我目前有點困惑微數據和schema.org。 microdata和schema.org是一樣的嗎?我閱讀GoogleMicrosoft文檔,但這並沒有幫助我獲得這兩個名稱之間的區別。添加微數據或schema.org的麪包屑搜索引擎優化Drupal 7

到目前爲止,我理解這一點我自己製作的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 breadcrumps。

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

到目前爲止,我檢查了所有這些代碼被執行:我在網上this fix,我想包括我自己的搜索引擎優化模塊,這樣上找到。但是這個主題不適用於我的頁面。 爲什麼該代碼無效?這可能與模塊breadcrumb有關?我知道這個輸出是垃圾,但我看不到結果。

如果我猜是正確的比由theme.inc line 1682ff theme_breadcrumb(...)創建的輸出而不是我的代碼。

這將是很好,如果有人可以幫助我,也如果你不知道我的問題的所有答案!

+1

關於標記的一個很好的問題,但我認爲你應該拿出關於Drupal的東西,並在另一個問題中移動它 – Baumr 2013-07-04 08:56:00

回答

10

microdata和schema.org是一樣的嗎?

不,他們不是!

Microdata是一個WHATWG html規範。這是爲了讓計算機更容易閱讀文檔的內容。

Schema.org是一個詞彙,用於描述一個項目。 Schema.org由Bing,Google和Yahoo引入。

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

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

http://schema.org/

是否有可能減少的HTML代碼的計數?

看看架構中的示例代碼。組織的網頁項的標記: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。

+0

如果我嘗試在http://www.google.com/webmasters/tools/中使用您的示例richsnippets breadcrumps不被識別。如果我使用其他字符替換'''' '''檢測到麪包屑但不能識別。 – rekire 2012-04-29 16:28:06

+0

@rekire我不知道你會如何解決這個問題。我複製粘貼了我在答案中寫入的示例代碼,但沒有發現問題。 – superhero 2012-04-29 19:19:39

+0

抱歉,延遲。這是[結果頁](http://www.google.com/webmasters/tools/richsnippets?url=http%3A%2F%2Ffiddle.jshell.net%2FFEhcE%2Fshow%2F)與我的麻煩基於[這個小提琴](http://jsfiddle.net/FEhcE/)。正如你可以看到谷歌顯示:* fiddle.jshell.net/FEhcE/show/* * fiddle.jshell.net>文學與小說>經典*。 – rekire 2012-05-01 08:43:58