Skip Navigation

[Resolved] Custom Post Type Breadcrumbs Path. Please advice.

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 8 replies, has 2 voices.

Last updated by terryR 6 years ago.

Assisted by: Nigel.

Author
Posts
#1176833
02-Parent-Category-Page.PNG
01-CPT-Taxonomies.PNG
03-Child-Category-Page.PNG

Happy New Year!

Hello, I would like to ask you if you can help me about the breadcrumbs path of a CPT I have recently developed.
1. Created the CPT
2. Created Custom Taxonomy
3. Assigned Parent/Child Categories to the Custom Posts

The result which I am expecting to see is the full path of the breadcrumb but it is showing only the CPT's main slug and aterwards the Custom Post Type's title. Images are attached for reference.
Please advice me if there is a way to make the full CPT path in the breadcrumbs area.

Thanks in advance.
Best Regards!

#1176890

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Terry

I'd say it rather depends on what is generating the breadcrumb path.

I'm guessing it comes from your theme.

Can you isolate the code in your theme's template files which generates the breadcrumbs and paste it here for me to see? (What is the theme?)

#1176896

Hello Nigel,
Thank you for the fast answer.

I managed to check what is the snipped code in the theme which controls the Breadcrumbs path.
Here it is:

===============================================================================================

// Custom Post Types
elseif ( is_singular() ) {
// Get the post type
$post_type = get_post_type();
// Get the post object
$post_type_object = get_post_type_object( $post_type );
// Get the post type archive
$post_type_archive = get_post_type_archive_link( $post_type );
// Add taxonomy link and separator
$html .= '<span class="item-cat item-custom-post-type-' . esc_attr( $post_type ) . '">labels->name ) . '">' . esc_attr( $post_type_object->labels->name ) . '</span>';
$html .= $separator;
// Add name of Post
$html .= '<span class="item-current item-' . $post->ID . '"><span class="bread-current bread-' . $post->ID . '" title="' . $post->post_title . '">' . $post->post_title . '</span></span>';
}

=======================================================================================

The theme which is used is Jevelin Theme.
Please if anything else is needed I will assist.
Best regards.

#1176922

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Terry

That's not quite what I was expecting, because it is displaying the breadcrumbs as Home > post type > post name and I had the impression from your question that it was displaying something like home > taxonomy term > post name and you wanted to expand taxonomy term to display the hierarchy of terms where relevant.

It seems like you have some overlap between the post type names and the taxonomy names, so I'm not sure what I'm looking at.

Can you clarify the breadcrumb structure you are aiming for, and perhaps I can take a look at your site to see for myself what the post types and taxonomies are.

I will mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site, even though I don't intend to make any changes.

#1176933

Hi, thank you. I have created a username and password from where you can login.
I try to display this kind of trail: /products > *parent category* > *child-category* ( and if possible if the child category has child category - on some posts is set - to display it after it too )

Thank you.

#1177003

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Terry

OK, I understand the requirements. This isn't really a Toolset issue (your theme is responsible for outputting this), but I'll take a look when I'm back in the morning, it shouldn't be too difficult to use get_terms to retrieve the terms, although there is one complication I notice.

On your site for the example Property Coverage post, you have only set the child term ("Property Coverage") and not the parent term(s), i.e. "Commercial insurance".

It will be somewhat more complicated if you don't apply the hierarchy of terms to the posts, is there some reason you cannot?

#1177011
Parent-Child.PNG

Hi Nigel. Thanks much for your help!
While I was adding content to the Post Types I was setting on the field ( attached image ) the current category and on the dropdown was selecting which will go for parent for this Category.
After updating the page the tick sign was applied only on the category which I set without having the parent category ticked.
Then I manually ( on a couple of Custom Posts ) assigned those ticks - which to be Primary Category and which to be Child ( as seen in the image attached ) Please advice if this is needed for me to make and I will scroll through the Post Types and tick the Primary categories on each post there to look exactly as in the image attached.

Thanks again for the help and hopefully we will get to resolve this.
Best Regards!

#1177653

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2019-01-04 at 12.22.47.png

I don't recognise that last screenshot with terms marked as 'primary' and a 'Make primary' link, it's not standard WordPress, but it is also not what I see on your site if I edit a ProtectOne Product post (see my screenshot).

In any case, you need to make sure that the whole hierarchy of terms is assigned to the post for this to work.

You'll need to edit the theme template and replace the whole block of code that produces the breadcrumbs with the following:

global $post;

// Produce an array with the taxonomy hierarchy
$hierarchy = _get_term_hierarchy('protectone-categories');

$lastEl = array_values(array_slice($hierarchy, -1))[0];

$hierarchy = array_keys($hierarchy);

$hierarchy[] = $lastEl[0];

// Get the assigned terms in the correct order
$terms = get_terms(array(
	'taxonomy' => 'protectone-categories',
	'orderby' => 'include',
	'object_ids' => $post->ID,
	'include' => $hierarchy,
));

$home = get_home_url();

// Build the html for the breadcrumbs
$output = "<a href='" . $home . "'>Home</a>";
foreach ($terms as $key => $term) {
	$link = get_term_link($term);
	$output .= " / <a href='" . $link . "'>" . $term->name . "</a>";
}
$output .= " / " . $post->post_title;

// Print the breadcrumbs
echo $output;

This needs to be inside php tags.

It will output the breadcrumbs in the format:

Home link > parent category link > child category link > grandchild category link > post title

Note that I didn't try and reproduce adding classnames etc. to the links, I'll leave that to you if you need it.

#1177699

My issue is resolved now. Thank you!