Function that returns the breadcrumb navigation
Categories: its own function
2010-08-24 Last update:
2009-06-01: Sun Posts
Breadcrumbs is a function that returns its own. Comes back with a link.
Whether there is not way to somewhere? I looked and thought, because there was only the plug was attached to the eye ... Innovation performance.
Place open to the public, and I think that if you come to the reference also to introduce a plug-in bread crumbs bother about, so I have created is easy.
Features of this function also returns the breadcrumb is where the page, not only category.
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




























