Paypalテーマでのぱんくず表記

フォーラム テンプレート(テーマ) Paypalテーマでのぱんくず表記

  • このトピックには6件の返信、2人の参加者があり、最後にtomozouにより9年、 12ヶ月前に更新されました。
7件の投稿を表示中 - 1 - 7件目 (全7件中)
  • 投稿者
    投稿
  • #69247
    tomozou
    参加者

    paypal_vermilionのテーマを使用しております。
    デフォルト仕様のパンくずの表記が、カテゴリが2階層になるとうまく表示されません。

    カテゴリBのページのぱんくずは、

    HOME>商品>商品ジャンル>カテゴリA>カテゴリB

    と、きれいに並びますが、このあとさらに下の商品ページに行きますと

    HOME>商品>商品ジャンル>カテゴリA>商品タイトル

    となり、カテゴリBが消えてしまいます。

    ご確認をお願いします。

    それと、ついでではないのですが、このパンくずの「商品」の表記を削除したいので
    その方法もご教授いただければと思います。
    よろしくお願いします。

    • このトピックはnanbuが10年前に変更しました。
    #69280
    nanbu
    キーマスター

    こんにちは。

    「Breadcrumb NavXT」をお使いですか?
    もしそうでしたら、カテゴリBが消えてしまうのはそのプラグインの仕様です。

    商品の削除方法についても、そちらのプラグインの情報を確認してください。

    #69300
    tomozou
    参加者

    ご回答ありがとうございます。

    Breadcrumb NavXTはそもそも知らなかったので、それを使わない状態でそうなったのですが、
    paypal_vermilionで使われているパンくずもそういう仕様だということでしょうか?

    また、
    「このパンくずの「商品」の表記を削除したいのでその方法もご教授いただければと思います。」
    へのご回答もできればお願いします。

    別のトピックスで、Breadcrumb NavXTを使った場合に「商品」の文字を消すソースは見つけましたが、
    paypal_vermilionテーマのパンくずはそれでは消えませんでした。

    #69420
    nanbu
    キーマスター

    失礼しました。プラグインではなく、組み込みの「パンくず」でしたね。
    ちょっと修正してみましたので、こちらのコードに書き換えてみていただけますでしょうか。
    ファイルは、paypal_vermilionの中のfunctions.phpです。かなり長いので、functions.phpそのものも添付しておきます。zipですので解凍してご利用ください。

    コードの中に、get_item_category_depth( ‘itemgenre’, true ); という行があります。第1引数は起点となるカテゴリーのスラッグです。デフォルトでは「商品ジャンル」カテゴリーが起点となります。第2引数は、その起点を含めるかどうかです。デフォルトでは「商品ジャンル」を含めていますので、これを外したい場合は、第2引数を false として下さい。

    ※コードを修正しました

    • この返信は10年前にnanbuが編集しました。
    • この返信は9年、 12ヶ月前にnanbuが編集しました。
    #69432
    tomozou
    参加者

    ありがとうございます。コードまで用意していただき大変うれしく思います。

    実際に組み込んでみたのですが、2点だけ再確認をお願いします。

    (1)商品詳細ページにおけるぱんくず

    HOME > 商品ジャンル > カテゴリA > カテゴリB > りんご

    と表記されますが、この時点で「カテゴリB」をクリックすると、カテゴリBの一覧ではなく、
    お勧め商品一覧へ飛びます。
    実際に作成しているサイトと、デフォルトでソースをほとんどいじっていない2つのサイトで
    試しましたがどちらも同じ導線となりました。

    (2)上記商品詳細ページで「商品」のリンクは出ないのですが、
    例えば、「カテゴリA」一覧などの上位層では「商品」が表記されてしまいます。
    こちらを消す事は難しいのでしょうか。

    以上です。よろしくお願いいたします。

    #69478
    nanbu
    キーマスター

    ご確認ありがとうございます。
    コードを修正しましたので、改めてこちらに記載します。少々ルールを変更しまして、
    起点の初期カテゴリーは「商品ジャンル(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);
    		}
    	}	
    
    • この返信は9年、 12ヶ月前にnanbuが編集しました。
    Attachments:
    You must be logged in to view attached files.
    #69567
    tomozou
    参加者

    ありがとうございます。
    確認して、正常に動作しましたので報告いたします。
    大変助かりました。

7件の投稿を表示中 - 1 - 7件目 (全7件中)
  • このトピックに返信するにはログインが必要です。