ぱんくずリンク滋賀県守山市のホームページ制作

ワードプレス

ぱんくずリンク

★プラグイン
Breadcrumb NavXT
————
★スクリプト
functions.php

/*
ぱんくずリンク
 */
function breadcrumb(){
    global $post;
    $str ='';
    if(!is_home()&&!is_admin()){
        $str.= '<div id="pankz"><div id="breadcrumb" class="cf"><div class="pankzHome">';
        $str.= '<a href="'. home_url() .'" itemprop="url"><span itemprop="title">ホーム</span></a></div>';
 
        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.='<div class="pankzCurrent"><a href="'. get_category_link($ancestor) .'" itemprop="url"><span itemprop="title">'. get_cat_name($ancestor) .'</span></a></div>';
                }
            }
        $str.='<div class="pankzCurrent"><a href="'. get_category_link($cat -> term_id). '" itemprop="url"><span itemprop="title">'. $cat-> cat_name . '</span></a></div>';
        } elseif(is_page()){
            if($post -> post_parent != 0 ){
                $ancestors = array_reverse(get_post_ancestors( $post->ID ));
                foreach($ancestors as $ancestor){
                    $str.='<div class="pankzCurrent"><a href="'. get_permalink($ancestor).'" itemprop="url"><span itemprop="title">'. get_the_title($ancestor) .'</span></a></div>';
                }
            }
        } 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.='<div class="pankzCurrent"><a href="'. get_category_link($ancestor).'" itemprop="url"><span itemprop="title">'. get_cat_name($ancestor). '</span></a></div>';
                }
            }
            $str.='<div class="pankzHere"><a href="'. get_category_link($cat -> term_id). '" itemprop="url"><span itemprop="title">'. $cat-> cat_name . '</span></a></div>';
        } else{
            $str.='<div>'. wp_title('', false) .'</div>';
        }
        $str.='</div></div>';
    }
    echo $str;
}

★挿入

<?php breadcrumb(); ?>

★CSS

#pankz {
	margin: 0 0 20px 0;
	text-align: left;
	padding: 0;
	height: 20px;
	display: block;
	position: relative;
	font-size: 12px;
	letter-spacing: 0.1em;
	background: #EFE2C2;
	border-radius: 10px;
	-webkit-border-radius: 10px;
	-moz-border-radius: 10px;
}

#breadcrumb {
	margin: 0;
	padding: 0;
	display: block;
	position: absolute;
	right: 0;
}


#breadcrumb a {
	color: #630;
}

#breadcrumb div:first-child {
	margin: 0;
	padding: 2px 10px 2px 45px;
	display: block;
	float: left;
	height: 16px;
	background: none;
}


#breadcrumb div {
	margin: 0;
	padding: 2px 10px 2px 45px;
	display: block;
	float: left;
	background: url(../img/common/pankz_home.png) no-repeat left center;
	height: 16px;
}

#breadcrumb div:last-child {
	margin: 0;
	padding: 2px 10px 2px 45px;
	display: block;
	float: left;
	background: #E8D3A4 url(../img/common/pankz_current.png) no-repeat left center;
	height: 16px;
	border-top-right-radius: 10px;
	-webkit-border-top-right-radius: 10px;
	-moz-border-top-right-radius: 10px;
	border-bottom-right-radius: 10px;
	-webkit-border-bottom-right-radius: 10px;
	-moz-border-bottom-right-radius: 10px;
}