返信先: Paypalテーマでのぱんくず表記
フォーラム › テンプレート(テーマ) › Paypalテーマでのぱんくず表記 › 返信先: Paypalテーマでのぱんくず表記
2014年4月2日 3:55 AM
#69478

キーマスター
ご確認ありがとうございます。
コードを修正しましたので、改めてこちらに記載します。少々ルールを変更しまして、
起点の初期カテゴリーは「商品ジャンル(itemgenre)」カテゴリーとなります。これを変更するには、header.phpテンプレートに有りますbreadcrumb()を、こちらのように書き換える必要があります。
breadcrumb( array(“id” => “breadcrumb”, “class” => “clearfix”), array(‘first’ => ‘itemgenre’, ‘display_first’ => true))
‘itemgenre’という所が起点のカテゴリースラッグです。
display_first をfalseにしますと起点が表示されなくなります。
こちらは、taxonomy には非対応です。
/***********************************************************
* パンクズリスト
***********************************************************/
global $cat_depth;
function breadcrumb($divOption = array("id" => "breadcrumb", "class" => "clearfix"), $option = array('first' => 'itemgenre', 'display_first' => true)){
global $post;
$str ='';
if(!is_home()&&!is_admin()){ /* !is_admin は管理ページ以外という条件分岐 */
$tagAttribute = '';
foreach($divOption as $attrName => $attrValue){
$tagAttribute .= sprintf(' %s="%s"', $attrName, $attrValue);
}
$str.= '<div'. $tagAttribute .'>';
$str.= '<ul>';
$str.= '<li><a href="'. home_url() .'/">HOME</a></li>';
$str.= '<li class="arrow">></li>';
if(is_category()) { //カテゴリーのアーカイブページ
$first_cat = get_category_by_slug($option['first']);
$first_cat_ancestors = array_reverse(get_ancestors( $first_cat->term_id, 'category' ));
if( !$option['display_first'] )
array_push( $first_cat_ancestors, $first_cat->term_id );
$cat = get_queried_object();
if($cat->parent != 0){
$ancestors = array_reverse(get_ancestors( $cat->term_id, 'category' ));
foreach($ancestors as $ancestor){
if( in_array($ancestor, $first_cat_ancestors) )
continue;
$str.='<li><a href="'. get_category_link($ancestor) .'">'. get_cat_name($ancestor) .'</a></li>';
$str.='<li class="arrow">></li>';
}
}
$str.='<li>'. $cat->name . '</li>';
} elseif( is_single() && usces_is_item($post->ID) ){ //商品詳細ページ
global $cat_depth;
get_item_category_depth( $option['first'], $option['display_first'] );
$cats = get_the_category( $post->ID );
$targets = array();
foreach( $cats as $cat ){
if( !isset( $cat_depth[$cat->term_id] ) )
continue;
$ob = $cat_depth[$cat->term_id];
$targets[$ob->item_depth] = $ob;
}
ksort($targets);
foreach($targets as $target){
$str .= '<li><a href="' . get_category_link( $target->term_id ) . '">' . $target->name . '</a></li>';
$str.='<li class="arrow">></li>';
}
$str .= '<li>' . esc_html($post->post_title) . '</li>';
} elseif(is_single()){ //ブログの個別記事ページ
$categories = get_the_category($post->ID);
$cat = $categories[0];
if($cat -> parent != 0){
$ancestors = array_reverse(get_ancestors( $cat -> cat_ID, 'category' ));
foreach($ancestors as $ancestor){
$str.='<li><a href="'. get_category_link($ancestor).'">'. get_cat_name($ancestor). '</a></li>';
$str.='<li class="arrow">></li>';
}
}
$str.='<li><a href="'. get_category_link($cat -> term_id). '">'. $cat-> cat_name . '</a></li>';
$str.='<li class="arrow">></li>';
$str.= '<li>'. $post -> post_title .'</li>';
} elseif(is_page()){ //固定ページ
if($post -> post_parent != 0 ){
$ancestors = array_reverse(get_post_ancestors( $post->ID ));
foreach($ancestors as $ancestor){
$str.='<li><a href="'. get_permalink($ancestor).'">'. get_the_title($ancestor) .'</a></li>';
$str.='<li class="arrow">></li>';
}
}
$str.= '<li>'. $post -> post_title .'</li>';
} elseif(is_date()){ //日付ベースのアーカイブページ
if(get_query_var('day') != 0){ //年別アーカイブ
$str.='<li><a href="'. get_year_link(get_query_var('year')). '">' . get_query_var('year'). '年</a></li>';
$str.='<li class="arrow">></li>';
$str.='<li><a href="'. get_month_link(get_query_var('year'), get_query_var('monthnum')). '">'. get_query_var('monthnum') .'月</a></li>';
$str.='<li class="arrow">></li>';
$str.='<li>'. get_query_var('day'). '日</li>';
} elseif(get_query_var('monthnum') != 0){ //月別アーカイブ
$str.='<li><a href="'. get_year_link(get_query_var('year')) .'">'. get_query_var('year') .'年</a></li>';
$str.='<li class="arrow">></li>';
$str.='<li>'. get_query_var('monthnum'). '月</li>';
} else { //年別アーカイブ
$str.='<li>'. get_query_var('year') .'年</li>';
}
} elseif(is_search()) { //検索結果表示ページ
$str.='<li>「'. get_search_query() .'」で検索した結果</li>';
} elseif(is_author()){ //投稿者のアーカイブページ
$str .='<li>投稿者 : '. get_the_author_meta('display_name', get_query_var('author')).'</li>';
} elseif(is_tag()){ //タグのアーカイブページ
$str.='<li>タグ : '. single_tag_title( '' , false ). '</li>';
} elseif(is_attachment()){ //添付ファイルページ
$str.= '<li>'. $post -> post_title .'</li>';
} elseif(is_404()){ //404 Not Found ページ
$str.='<li>404 Not found</li>';
} else{ //その他
$str.='<li>'. wp_title('', true) .'</li>';
}
$str.='</ul>';
$str.='</div>';
}
echo $str;
}
function get_item_category_depth( $parent = 'itemgenre', $first = true ){
global $cat_depth;
$cat_depth = array();
$depth = 1;
$cat_ob = get_category_by_slug( $parent );
$cat_ob->item_depth = $depth;
if( $first )
$cat_depth[$cat_ob->term_id] = $cat_ob;
add_item_category_depth($cat_ob, $depth);
ksort($cat_depth);
}
function add_item_category_depth($parent_ob, $depth){
global $cat_depth;
$depth++;
$childargs = array(
'type' => 'post',
'parent' => $parent_ob->term_id,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'pad_counts' => false );
$childcats = get_categories( $childargs );
if( 0 < count($childcats) ){
foreach( $childcats as $childcat ){
if( 100 < $depth ) break;
$childcat->item_depth = $depth;
$cat_depth[$childcat->term_id] = $childcat;
add_item_category_depth($childcat, $depth);
}
}
-
この返信は11年前に
nanbuが編集しました。