워드프레스 breadcrumb에 대해서 채택완료
Copy
//breadcrumbfunction 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개
채택된 답변
+20 포인트
9년 전
질문 대로 라면
$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>';
하면 되겠네요
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
9년 전
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
그리고
[code]
if(!is_home()&&!is_admin()){ /* !is_admin は管理ページ以外という条件分岐 */
[/code]
이부분이 admin페이지 이외 적용하라는 조건문이라는데,
그 조건을 빼면 어떻게 되나요?
if(..