パンくずリストを制御する基本的な内容と、パンくずリストの最後にページタイトル(ページ名称)を追加する方法に関するメモ。
tpl.phpでの出力パンくずリストを表示するには、テンプレート ( page.tpl.php とか) 内では、
<?php print $breadcrumb; ?>みたいに、変数 $breadcrumb を出力してあげます。
template.php でのオーバーライドパンくず表示をオーバーライドする時は、 template.php 内で、
function phptemplate_breadcrumb($breadcrumb) {
if (!empty($breadcrumb)) {
return '<div class="breadcrumb">'. implode(' > ', $breadcrumb) .'</div>';
}
}と、配列 $breadcrumb を連結して return してあげます。
関数名の優先順位は、
mytheme_breadcrumb < phptemplate_breadcrumb < theme_breadcrumb
モジュールの 「 Menu Breadcrumb 」とかを使えば、現在のページ名称を パンくず に表示することもできますが、「 Taxonomy breadcrumb 」 とかを使っていると、パンくず に ページ名称を表示する方法が見当たりません。
そこで、template.php でオーバーライドする際に、
function phptemplate_breadcrumb($breadcrumb) {
//ページのタイトルを取得
$title = drupal_get_title();
//パンくずリストの配列の最後に、タイトルを追加
array_push($breadcrumb,$title);
if (!empty($breadcrumb)) {
return '<div class="breadcrumb">'. implode(' > ', $breadcrumb) .'</div>';
}
}のようにして、あげることで、モジュールが生成したパンくずリストに現在ページのタイトル(ページ名称)を追加することが出来ます。