返回Breadcrumb导航的功能,
分类: 自己的功能
2010-08-24最后更新:
2009-06-01:孙文章
面包是一个函数,返回自己的。 回来一个环节。
是否有不某处的方式? 我看了看,并认为,因为当时只有插头贴在眼睛上......创新的表现。
将向公众开放,我想,如果你来参考,还引进1插件在面包屑操心,所以我创造了很容易。
这个函数的功能也将返回的痕迹页,不仅类。
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




























