Funzione che restituisce la navigazione breadcrumb
Categorie: la sua funzione propria
2010/08/24 Ultimo aggiornamento:
2009/06/01: Messaggi Sun
Breadcrumbs è una funzione che restituisce proprio. Torna con un link.
Se non c'è modo per da qualche parte? Ho guardato e ho pensato, perché non c'era solo la spina è stata allegata agli occhi ... capacità di innovazione.
Luogo aperto al pubblico, e penso che se si raggiunge il riferimento anche per introdurre un plug-in pangrattato preoccuparsi, così ho creato è facile.
Caratteristiche di questa funzione restituisce anche il breadcrumb è dove la pagina, non solo categoria.
function get_pankuzu_navi( $page='page', $id=0 ) {
$output = '<a href="' . get_bloginfo('url') . '">ホーム</a> >> ';
// idの指定が無い場合は処理しない
if($id == 0) {
return $output;
}
if($page == 'page') {
$the_post = get_post($id);
// 親ページを取得
$ancestor = get_post_ancestors($the_post->parent);
if(count($ancestor) > 0) {
// 後方(最上階層)からループ
for($i=(count($ancestor) - 1); $i > -1; $i--) {
$the_page = get_page($ancestor[$i]);
$output .= '<a href="' . get_permalink($ancestor[$i]) . '">' . $the_page->post_title . '</a> >> ';
}
}
} else {
$the_cat = get_the_category($id);
$the_cat = $the_cat[0];
$output .= get_category_parents($the_cat->cat_ID, true, ' ≫ ');
}
return $output;
}
テンプレートファイルのfunctions.phpに載せてやると良いかと思います。
引数ですが、
$page : ナビを返すリストの種類('page' or 'category')
ページの階層表示もしくはカテゴリの階層表示か選択します。
$id : post_id
下記のように使います。
// page.phpの場合
echo get_pankuzu_navi('page', $post->ID);
// single.phpの場合
echo get_pankuzu_navi('category', $post->ID);
返ってくる形が気に食わない場合は、好きなように改造すれば良いと思います。
- タグ
- function , WordPress備忘録 , パンくずナビ , パンくずリスト , 関数
- トラックバックURL




























