Breadcrumbs: Display all categories in hierarchical order

Hi @Rad, hi there,

I’d love my blog posts to display all categories in hierarchical order. I’ve seen code snippets in several other threads but they did not accomplish what I need. This is what I have so far, but categories will be displayed in a weird (alphabetical?) order?

// Breadcrumbs
// =============================================================================
// See https://theme.co/apex/forum/t/pro-child-breadcrumbs-with-category-where-is-breadcrumbs-php/22940
add_filter('x_breadcrumbs_data', 'post_parent_trail', 999999, 2);

function post_parent_trail ($crumbs, $args) {
	if ( is_singular('post') ) {
		$category = get_the_category( get_the_ID() );
		$numberOfCrumbs = count( $crumbs );
		if ( count( $category ) > 0 ) {
			for ($zaehler = 0; $zaehler < count( $category ); $zaehler++) {
				$crumbs[$zaehler + $numberOfCrumbs]['label'] = $category[$zaehler]->name;
				$crumbs[$zaehler + $numberOfCrumbs]['url'] = get_category_link( $category[$zaehler]->term_id );
			}
    	}
  	}
  	return $crumbs;
}

I was hoping you would have a snippet available?

Cheers

Hi There,

Thanks for writing in! Regretfully this isn’t a feature offered by X. It could be possible with custom development, but this would be outside the scope of support we can offer. You may wish to consult a developer to assist you with this. X is quite extensible with child themes, so there are plenty of possibilities.

Thanks for understanding,

Hi @friech,
I’ve seen your own colleagues actually answer this question in this forum… Also, it’s not missing a lot! :confused:
Martin

Hi Martin,

Please try with this code instead:

Hope it helps :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.