最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Custom post type not displayed in breadcrumbs on archive page

programmeradmin5浏览0评论

I created new custom post type and am having problem with displaying the post type name in breadcrumbs.

It should display "Home » Study » test study", but it displays Home » » test study". Site: CLICK

Also, Study (title) should be displayed on the left of breadcrumbs on the site: CLICK

On other pages breadcrumbs and titles work fine.

And basically all page structure is defined with a plugin (PMC page builder). So I can not really edit php files if I do not want to lose changes when the plugin updates.

Please tell me if any further clarification is needed. Best regards!

Edit: Breadcrumbs code from functions.php:

/* custom breadcrumb */
function pmc_breadcrumb($title = false) {

global $pmc_data;
$breadcrumb = '';
if (!is_home()) {
    if($title == false){
        $breadcrumb .= '<a href="';
        $breadcrumb .=  home_url();
        $breadcrumb .=  '">';
        $breadcrumb .= __('Home', 'pmc-themes');
        $breadcrumb .=  "</a> &#187; ";
    }
    if (is_single()) {
        if (is_single()) {
            $name = '';
            if(!get_query_var($pmc_data['port_slug']) && !get_query_var('product')){
                $category = get_the_category(); +
                $category_id = get_cat_ID($category[0]->cat_name);
                $category_link = get_category_link($category_id);                   
                $name = '<a href="'. esc_url( $category_link ).'">'.$category[0]->cat_name .'</a>';
            }
            else{
                $taxonomy = 'portfoliocategory';
                $entrycategory = get_the_term_list( get_the_ID(), $taxonomy, '', ',', '' );
                $catstring = $entrycategory;
                $catidlist = explode(",", $catstring);  
                $name = $catidlist[0];
            }
            if($title == false){
                $breadcrumb .= $name .' &#187; <span>'. get_the_title().'</span>';
            }
            else{
                $breadcrumb .= get_the_title();
            }
        }   
    } elseif (is_page()) {
        $breadcrumb .=  '<span>'.get_the_title().'</span>';
    }
    elseif(get_query_var('portfoliocategory')){
        $term = get_term_by('slug', get_query_var('portfoliocategory'), 'portfoliocategory'); $name = $term->name; 
        $breadcrumb .=  '<span>'.$name.'</span>';
    }   
    else if(is_tag()){
        $tag = get_query_var('tag');
        $tag = str_replace('-',' ',$tag);
        $breadcrumb .=  '<span>'.$tag.'</span>';
    }
    else if(is_search()){
        $breadcrumb .= __('Search results for ', 'pmc-themes') .'"<span>'.get_search_query().'</span>"';            
    } 
    else if(is_category()){
        $cat = get_query_var('cat');
        $cat = get_category($cat);
        $breadcrumb .=  '<span>'.$cat->name.'</span>';
    }
    else if(is_archive()){
        $breadcrumb .=  '<span>'.__('Archive','pmc-themes').'</span>';
    }   
    else{
        $breadcrumb .=  'Home';
    }
    if(function_exists('is_shop')){
        if(is_product() || is_product_category() || is_shop()){
            $breadcrumb = ''; 
            woocommerce_breadcrumb();
        }
    }
}
return $breadcrumb ;
}

EDIT 2:

I turned on debuger and I get this errors: "Notice: Undefined offset: 0 in..." and "Trying to get property of non-object in...". Both pointing to the code above, more specificaly to:

f(!get_query_var($pmc_data['port_slug']) && !get_query_var('product')){
                $category = get_the_category(); +
                $category_id = get_cat_ID($category[0]->cat_name);
                $category_link = get_category_link($category_id);                   
                $name = '<a href="'. esc_url( $category_link ).'">'.$category[0]->cat_name .'</a>';

I created new custom post type and am having problem with displaying the post type name in breadcrumbs.

It should display "Home » Study » test study", but it displays Home » » test study". Site: CLICK

Also, Study (title) should be displayed on the left of breadcrumbs on the site: CLICK

On other pages breadcrumbs and titles work fine.

And basically all page structure is defined with a plugin (PMC page builder). So I can not really edit php files if I do not want to lose changes when the plugin updates.

Please tell me if any further clarification is needed. Best regards!

Edit: Breadcrumbs code from functions.php:

/* custom breadcrumb */
function pmc_breadcrumb($title = false) {

global $pmc_data;
$breadcrumb = '';
if (!is_home()) {
    if($title == false){
        $breadcrumb .= '<a href="';
        $breadcrumb .=  home_url();
        $breadcrumb .=  '">';
        $breadcrumb .= __('Home', 'pmc-themes');
        $breadcrumb .=  "</a> &#187; ";
    }
    if (is_single()) {
        if (is_single()) {
            $name = '';
            if(!get_query_var($pmc_data['port_slug']) && !get_query_var('product')){
                $category = get_the_category(); +
                $category_id = get_cat_ID($category[0]->cat_name);
                $category_link = get_category_link($category_id);                   
                $name = '<a href="'. esc_url( $category_link ).'">'.$category[0]->cat_name .'</a>';
            }
            else{
                $taxonomy = 'portfoliocategory';
                $entrycategory = get_the_term_list( get_the_ID(), $taxonomy, '', ',', '' );
                $catstring = $entrycategory;
                $catidlist = explode(",", $catstring);  
                $name = $catidlist[0];
            }
            if($title == false){
                $breadcrumb .= $name .' &#187; <span>'. get_the_title().'</span>';
            }
            else{
                $breadcrumb .= get_the_title();
            }
        }   
    } elseif (is_page()) {
        $breadcrumb .=  '<span>'.get_the_title().'</span>';
    }
    elseif(get_query_var('portfoliocategory')){
        $term = get_term_by('slug', get_query_var('portfoliocategory'), 'portfoliocategory'); $name = $term->name; 
        $breadcrumb .=  '<span>'.$name.'</span>';
    }   
    else if(is_tag()){
        $tag = get_query_var('tag');
        $tag = str_replace('-',' ',$tag);
        $breadcrumb .=  '<span>'.$tag.'</span>';
    }
    else if(is_search()){
        $breadcrumb .= __('Search results for ', 'pmc-themes') .'"<span>'.get_search_query().'</span>"';            
    } 
    else if(is_category()){
        $cat = get_query_var('cat');
        $cat = get_category($cat);
        $breadcrumb .=  '<span>'.$cat->name.'</span>';
    }
    else if(is_archive()){
        $breadcrumb .=  '<span>'.__('Archive','pmc-themes').'</span>';
    }   
    else{
        $breadcrumb .=  'Home';
    }
    if(function_exists('is_shop')){
        if(is_product() || is_product_category() || is_shop()){
            $breadcrumb = ''; 
            woocommerce_breadcrumb();
        }
    }
}
return $breadcrumb ;
}

EDIT 2:

I turned on debuger and I get this errors: "Notice: Undefined offset: 0 in..." and "Trying to get property of non-object in...". Both pointing to the code above, more specificaly to:

f(!get_query_var($pmc_data['port_slug']) && !get_query_var('product')){
                $category = get_the_category(); +
                $category_id = get_cat_ID($category[0]->cat_name);
                $category_link = get_category_link($category_id);                   
                $name = '<a href="'. esc_url( $category_link ).'">'.$category[0]->cat_name .'</a>';
Share Improve this question edited Sep 4, 2015 at 6:00 Martin Peternel asked Sep 3, 2015 at 11:24 Martin PeternelMartin Peternel 311 silver badge8 bronze badges 2
  • 2 It would really help if can show some code. Breadcrumbs aren't build in, so it is impossible for anyone to know what your code looks like that displays this feature – Pieter Goosen Commented Sep 3, 2015 at 11:28
  • thank you Pieter, I have updated the question. I hope this is what you wanted to see – Martin Peternel Commented Sep 3, 2015 at 11:47
Add a comment  | 

1 Answer 1

Reset to default 2

So I figured out, that my theme was not designed to handle custom post types (at least not via the archive). The solution was to edit the code as shown below. Comments inserted where changes were made:

function pmc_breadcrumb($title = false) {

global $pmc_data;
$breadcrumb = '';
if (!is_home()) {
    if($title == false){
        $breadcrumb .= '<a href="';
        $breadcrumb .=  home_url();
        $breadcrumb .=  '">';
        $breadcrumb .= __('Home', 'pmc-themes');
        $breadcrumb .=  "</a> &#187; ";
    }
    if (is_single()) {
        if (is_single()) {
            $name = '';
            if(!get_query_var($pmc_data['port_slug']) && !get_query_var('product') && !get_query_var('study')/*<-- STUDY ADDED*/){
                $category = get_the_category(); +
                $category_id = get_cat_ID($category[0]->cat_name);
                $category_link = get_category_link($category_id);                   
                $name = '<a href="'. esc_url( $category_link ).'">'.$category[0]->cat_name .'</a>';
            }
            //ADDED THIS ELSE IF//
            else if(!get_query_var($pmc_data['port_slug']) && !get_query_var('product') && get_query_var('study')){                 
                $name = '<a href="../">'.__('Studies', 'pmc-themes').'</a>';
            }               
            else{
                $taxonomy = 'portfoliocategory';
                $entrycategory = get_the_term_list( get_the_ID(), $taxonomy, '', ',', '' );
                $catstring = $entrycategory;
                $catidlist = explode(",", $catstring);  
                $name = $catidlist[0];
            }
            if($title == false){
                $breadcrumb .= $name .' &#187; <span>'. get_the_title().'</span>';
            }
            else{
                $breadcrumb .= get_the_title();
            }
        }   
    }       
    else if (is_page()) {
        $breadcrumb .=  '<span>'.get_the_title().'</span>';
    }
    else if(get_query_var('portfoliocategory')){
        $term = get_term_by('slug', get_query_var('portfoliocategory'), 'portfoliocategory'); $name = $term->name; 
        $breadcrumb .=  '<span>'.$name.'</span>';
    }   
    else if(is_tag()){
        $tag = get_query_var('tag');
        $tag = str_replace('-',' ',$tag);
        $breadcrumb .=  '<span>'.$tag.'</span>';
    }
    /*****I ADDED THIS TO SHOW ON ARCIVE PAGES******/   
    else if(is_archive()){
        $breadcrumb .= '<span class="span-studies">'.__('Studies', 'pmc-themes').'<span>';      
    }
    /*****end of my edit******/
    else if(is_search()){
        $breadcrumb .= __('Search results for ', 'pmc-themes') .'"<span>'.get_search_query().'</span>"';            
    } 
    else if(is_category()){
        $cat = get_query_var('cat');
        $cat = get_category($cat);
        $breadcrumb .=  '<span>'.$cat->name.'</span>';
    }
    else if(is_archive()){
        $breadcrumb .=  '<span>'.__('Archive','pmc-themes').'</span>';
    }   
    else{
        $breadcrumb .=  'Home';
    }
    if(function_exists('is_shop')){
        if(is_product() || is_product_category() || is_shop()){
            $breadcrumb = ''; 
            woocommerce_breadcrumb();
        }
    }
}  
return $breadcrumb;

}
发布评论

评论列表(0)

  1. 暂无评论