[WordPress] パンくずリストに「カテゴリ」を追加したいのですが。

スポンサーリンク

Question

パンくずリストを持っているプレミアムなワード プレス テーマが投稿ページに (カテゴリおよびサブカテゴリ) の項目を表示しないのです。

たとえば下記のように表示したい。

ホーム > カテゴリ > サブ カテゴリ > 投稿タイトル

代わりにそれはこのようなが表示されます: ホーム > ポスト タイトル

// BREADCRUMBS

if ( ! function_exists( ‘ishyoboy_get_breadcrumbs’ ) ) {
function ishyoboy_get_breadcrumbs() {

global $ish_options, $ish_woo_id;

$return = ”;

$return .= ‘<div class=”ish-pb-breadcrumbs”><div><div>’ . “\n”;

if ( ! is_front_page() ) {
if ( function_exists(‘is_woocommerce’) ) {
if ( !is_woocommerce() && !is_woocommerce_page() ){
$return .= ‘<a class=”ish-pb-breadcrumbs-home” href=”‘;
$return .= home_url();
$return .= ‘”>';
$return .= ‘<span>’ . __( ‘Home’, ‘ishyoboy’ ) . ‘</span>';
$return .= “</a> &gt; “;
}

}
else{
$return .= ‘<a class=”ish-pb-breadcrumbs-home” href=”‘;
$return .= home_url();
$return .= ‘”>';
$return .= ‘<span>’ . __( ‘Home’, ‘ishyoboy’ ) . ‘</span>';
$return .= “</a> &gt; “;
}

}
else {
$return .= ‘<span class=”ish-pb-breadcrumbs-home”>';
$return .= ‘<span>’ . __( ‘Home’, ‘ishyoboy’ ) . ‘</span>';
$return .= “</span>”;
}

if ( !is_front_page() && is_home() ) {
global $page;
$return .= $page->post_title;
}

if ( is_archive() && ‘post’ == get_post_type() && ! is_category() && ( !function_exists(‘is_woocommerce’) || !is_woocommerce() ) ) {
$hpage = get_page( get_option( ‘page_for_posts’ ) );
if ( ‘page’ == get_option(‘show_on_front’) && isset($hpage) && ” != $hpage ){
$return .= get_page_parents($hpage->ID, TRUE, ‘ &gt; ‘, FALSE );
}
if ( is_day() ) :
$return .= sprintf( __( ‘Daily Archives: %s’, ‘ishyoboy’ ), ‘<span>’ . get_the_date() . ‘</span>’ );
elseif ( is_month() ) :
$return .= sprintf( __( ‘Monthly Archives: %s’, ‘ishyoboy’ ), ‘<span>’ . get_the_date( _x( ‘F Y’, ‘monthly archives date format’, ‘ishyoboy’ ) ) . ‘</span>’ );
elseif ( is_year() ) :
$return .= sprintf( __( ‘Yearly Archives: %s’, ‘ishyoboy’ ), ‘<span>’ . get_the_date( _x( ‘Y’, ‘yearly archives date format’, ‘ishyoboy’ ) ) . ‘</span>’ );
else :
$return .= __( ‘Archives’, ‘ishyoboy’ );
endif;
}
else if ( is_archive() && ‘post’ != get_post_type() && ( !function_exists(‘is_woocommerce’) || !is_woocommerce() ) ) {

$type = get_post_type( get_the_ID() );

$obj = get_post_type_object( $type );
if ( is_object( $obj ) ){
$return .= $obj->labels->name;
}

}

if ( (is_category() || is_single()) && ( ( !function_exists(‘is_woocommerce_page’) || !function_exists(‘is_woocommerce’ ) ) || ( !is_woocommerce() && !is_woocommerce_page() ) ) ) {

$post_id = ish_get_the_ID();
$post_type = get_post_type();

switch ($post_type){
case ‘portfolio-post’ :
$terms = get_the_terms($post_id, ‘portfolio-category’ );
$term = ( ! empty( $terms ) ) ? array_pop($terms) : ”;

if (isset($ish_options[‘page_for_custom_post_type_portfolio-post’]) && ‘-1′ != $ish_options[‘page_for_custom_post_type_portfolio-post’]){

$portfolio_page = get_page($ish_options[‘page_for_custom_post_type_portfolio-post’]);
$separator = ” &gt; “;
$return .= ‘<a href=”‘ . get_page_link( $ish_options[‘page_for_custom_post_type_portfolio-post’] ) . ‘” title=”‘ . esc_attr( sprintf( __( “View all posts in %s” , ‘ishyoboy’ ), $portfolio_page->post_title ) ) . ‘”>’.$portfolio_page->post_title.'</a>’ . $separator;
}

if ( ! empty( $term ) ){
$return .= get_term_parents($term->term_id, ‘portfolio-category’, TRUE, ‘ &gt; ‘, FALSE );
}
break;

// from here ==========>>

case ‘post’ :

if ( is_category() ){
global $cat;
$category = get_category($cat);
if ( $category->parent && ( $category->parent != $category->term_id ) ){
$return .= get_category_parents($category->parent, TRUE, ‘ &gt; ‘, FALSE );
}
$return .= single_cat_title(”, false);
}
else{
$category = get_the_category();
if ( is_object( $category ) ){
$ID = $category[0]->cat_ID;
$return .= get_category_parents($ID, TRUE, ‘ &gt; ‘, FALSE );
}
}
break;

// to here ==========>>

default :
$type = get_post_type( get_the_ID() );

$obj = get_post_type_object( $type );
if ( is_object( $obj ) ){
$return .= ‘<a href=”‘ . get_post_type_archive_link( $type ) .'”>’ . $obj->labels->name . ‘</a> &gt; ‘;
}

}
}
else if ( ( function_exists(‘is_woocommerce_page’) && function_exists(‘is_woocommerce’) ) && (is_woocommerce() || is_woocommerce_page() )){
ob_start();
woocommerce_breadcrumb(array(
‘delimiter’ => ‘ &gt; ‘,
‘wrap_before’ => ”,
‘wrap_after’ => ”,
‘before’ => ”,
‘after’ => ”,
‘home’ => ‘<span class=”ish-pb-breadcrumbs-home”><span>’ . _x( ‘Home’, ‘breadcrumb’, ‘woocommerce’ ) . ‘</span></span>’,
));
$return .= ob_get_contents();
ob_end_clean();
ob_end_flush();
}
else if (is_tax()){
if (is_tax(‘portfolio-category’)){

$current_term = get_queried_object();

if ( !empty($current_term) ){
//var_dump($current_term);

if (isset($ish_options[‘page_for_custom_post_type_portfolio-post’]) && ‘-1′ != $ish_options[‘page_for_custom_post_type_portfolio-post’]){

$portfolio_page = get_page($ish_options[‘page_for_custom_post_type_portfolio-post’]);
$separator = ” &gt; “;
$return .= ‘<a href=”‘ . get_page_link( $ish_options[‘page_for_custom_post_type_portfolio-post’] ) . ‘” title=”‘ . esc_attr( sprintf( __( “View all posts in %s” , ‘ishyoboy’ ), $portfolio_page->post_title ) ) . ‘”>’.$portfolio_page->post_title.'</a>’ . $separator;
}

if ($current_term->parent != 0 ){
$return .= get_term_parents($current_term->parent, ‘portfolio-category’, TRUE, ‘ &gt; ‘, FALSE );
}

$return .= $current_term->name;
}
}
}
else if (is_page()){
global $post;

if ($post->post_parent != 0 ){
$return .= get_page_parents($post->post_parent, TRUE, ‘ &gt; ‘, FALSE );
}
}

if (!function_exists(‘is_woocommerce_page’) || !is_woocommerce_page()){
if(is_single()) {$return .= get_the_title();}
if(is_page()) {
global $post;
$frontpage = get_option(‘page_on_front’);

if ( $frontpage && $frontpage == $post->ID){
/*$return .= ‘<a class=”home” href=”‘;
$return .= home_url();
$return .= ‘”>';
$return .= ‘<span>’ . __( ‘Home’, ‘ishyoboy’ ) . ‘</span>';
$return .= “</a>”;*/
} else {
$return .= get_the_title();
}
}
if(is_tag()){ $return .= __( ‘Tag: ‘, ‘ishyoboy’ ) . single_tag_title(”,FALSE); }
if(is_404()){ $return .= __( ‘404 – Page not Found’, ‘ishyoboy’ ); }
if(is_search()){ $return .= __( ‘Search’, ‘ishyoboy’ ); }
if(is_year()){ $return .= get_the_time(‘Y’); };
}

$return .= ‘</div></div></div>';

return $return;
}
}

if ( !function_exists(‘the_post_thumbnail_caption’) ) {
function the_post_thumbnail_caption(){

$thumb = get_post_thumbnail_id();

if ( ! empty( $thumb ) ){
$thumb_object = get_post( $thumb );
if ( ! empty( $thumb_object ) ) {
echo ‘<div class=”wp-caption”><p class=”wp-caption-text”>’ . $thumb_object->post_excerpt . ‘</p></div>';
}
}

}
}

if ( !function_exists(‘get_the_post_thumbnail_caption’) ) {
function get_the_post_thumbnail_caption(){

$thumb = get_post_thumbnail_id();

if ( ! empty( $thumb ) )
return get_post( $thumb )->post_excerpt;

return null;
}
}

if ( ! function_exists( ‘ishyoboy_activate_fancybox_on_blog_single’ ) ) {
function ishyoboy_activate_fancybox_on_blog_single() {

if ( is_singular() && !is_singular( ‘product’ ) ){
?>
<script type=”text/javascript”>
jQuery(document).ready(function($){
var thumbnails = jQuery(“a:has(img)”).not(“.nolightbox”).filter( function() { return /\.(jpe?g|png|gif|bmp)$/i.test(jQuery(this).attr(‘href’)) });

if ( thumbnails.length > 0){
thumbnails.addClass( ‘openfancybox-image’ ).attr( ‘rel’, ‘fancybox-post-image-<?php the_ID() ?>’);
}
});
</script>
<?php
}

}
}
add_action( ‘wp_head’, ‘ishyoboy_activate_fancybox_on_blog_single’ );

if ( ! function_exists( ‘ishyoboy_dummy_functions’ ) ) {
function ishyoboy_dummy_functions() {

if ( false ) {
posts_nav_link();
wp_link_pages();
$args = ”;
add_theme_support( ‘custom-header’, $args );
add_theme_support( ‘custom-background’, $args );
}

}
}

上記のコードで行った変更:

 case ‘post’ :
$terms = get_the_terms($post_id, ‘category’ );
$term = ( ! empty( $terms ) ) ? array_pop($terms) : ”;
if ( ! empty( $term ) ){
$return .= get_term_parents($term->term_id, ‘category’, TRUE, ‘ &gt; ‘, FALSE );
}

答え

カテゴリ得ることができますが、複数のカテゴリを持つことができ、ランディング ページのカテゴリは、メタデータにアクセスできます。 テンプレート階層 ページを確認しましたところ、WP 分類を処理する方法のしっかりした理解を持っているかが重要です。

私の提案は、カテゴリ ページにしているすべての余分なロジックを停止し、カテゴリの名前を把握することです。

http://stackoverflow.com/questions/27412398/i-want-to-add-category-to-my-wp-breadcrumbs

スポンサーリンク

Leave a Reply