워드프레스 breadcrumb에 대해서

워드프레스 breadcrumb에 대해서

QA

워드프레스 breadcrumb에 대해서

본문

 
 
//breadcrumb
function breadcrumb($navOption = array("id" => "breadcrumb", "class" => "clearfix")){
	global $post;
	$str ='';
	if(!is_home()&&!is_admin()){ /* !is_admin は管理ページ以外という条件分岐 */
		$tagAttribute = '';
		foreach($navOption as $attrName => $attrValue){
			$tagAttribute .= sprintf(' %s="%s"', $attrName, $attrValue);
		}
		$str.= '<nav'. $tagAttribute .'>';
		$str.= '<ol class="page_nav">';
		$str.= '<li><a href="http://사이트주소">HOME</a></li>';
		
		if(is_category()) {		                //カテゴリーのアーカイブページ
			$cat = get_queried_object();
			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>'. $cat -> name . '</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><a href="'. get_category_link($cat -> term_id). '">'. $cat-> cat_name . '</a></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>'. $post -> post_title .'</li>';
		} elseif(is_date()){
			if( is_year() ){
				$str.= '<li>' . get_the_time('Y') . '年</li>';
			} else if( is_month() ){
				$str.= '<li><a href="' . get_year_link(get_the_time('Y')) .'">' . get_the_time('Y') . '年</a></li>';
				$str.= '<li>></li>';
				$str.= '<li>' . get_the_time('n') . '月</li>';
			} else if( is_day() ){
				$str.= '<li><a href="' . get_year_link(get_the_time('Y')) .'">' . get_the_time('Y') . '年</a></li>';
				$str.= '<li>></li>';
				$str.= '<li><a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('n') . '月</a></li>';
				$str.= '<li>></li>';
				$str.= '<li>' . get_the_time('j') . '日</li>';
			}
			if(is_year() && is_month() && is_day() ){
				$str.= '<li>' . wp_title('', false) . '</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.='</ol>';
		$str.='</nav>';
	}
	echo $str;
}

사이트 제작 중에 일부분을 워드프레스로 제작하고 있습니다.
function.php부분에서 breadcrumb을 만들고 있는데,
HOME > ブログ > 지금 있는 페이지 
를 표현하고 싶은데,
위 코드로는 ブログ부분에 카테고리 일람으로 이동하네요...
저 부분도 워드프레스 밖에 있는 http://사이트주소/blog/index.html 이곳으로 이동하고 싶은데
어디를 어찌 변경해야 할지 모르겠습니다.
혹시 아시는 분 계시면 부탁드립니다!! 알려주세요...
열심히 구글링 중입니다 ㅠ ㅠ (검색도 참으로 어렵네요 ㅎㅎ)

이 질문에 댓글 쓰기 :

답변 1

질문 대로 라면 

$str.='<li><a href="'. get_category_link($ancestor).'">'. get_cat_name($ancestor). '</a></li>';

$str.='<li><a href="http://사이트주소/blog/index.html">'. get_cat_name($ancestor). '</a></li>';

하면 되겠네요

zzzz님 감사합니다 일단 해볼께요!! ^^
그리고
 


 if(!is_home()&&!is_admin()){ /* !is_admin は管理ページ以外という条件分岐 */

이부분이 admin페이지 이외 적용하라는 조건문이라는데,
그 조건을 빼면 어떻게 되나요?
if(..

답변을 작성하시기 전에 로그인 해주세요.
전체 190
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT