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>';
  • 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 Sep 3 '15 at 11:28
  • thank you Pieter, I have updated the question. I hope this is what you wanted to see – Martin Peternel Sep 3 '15 at 11:47
1

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();
            }
        }   
    }       
    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>';
    }
    /******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 ;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.