Diwakar Academy

  • Home
  • WordPress
  • About Us
  • Contact Us
You are here: Home / WordPress / Taxonomy Terms in Breadcrumbs

October 11, 2023

Taxonomy Terms in Breadcrumbs

Spread the love

Taxonomy Terms in Breadcrumbs. I believe there are three different scenarios:

Table of Contents

Toggle
  • Non-hierarchical taxonomy
  • Taxonomies with hierarchy

1. If the category system is not organized in a hierarchy.

2. If the category system is hierarchical but a post can only have one category selected.

3. If the category system is hierarchical, and posts can have multiple categories from the same tree selected.

Non-hierarchical taxonomy

Taxonomies that work like post tags are simple to handle. The easiest way to display the term links is by using the function called “the_terms().“

global $post; // this will help if you would use this code inside a custom function

$rd_post_id = $post->ID; // current post ID

$rd_taxonomy = ‘region’; // taxonomy name

// the third argument is what you want to add before the navigation, you can leave it empty

// the fourth argument is term link separator , | / •

the_terms( $rd_post_id, $rd_taxonomy, ‘Navigation: ‘, ‘ / ‘ );

Taxonomies with hierarchy

These taxonomies work like categories.

1. When only one term is selected, you can use the “the_terms()” function, just like in the previous code example.

2. When a tree of terms is selected, it looks like this:

In this situation, the order of the terms is crucial for us.

echo '<div id="kroshki">You are here:';

$rd_taxonomy = 'region'; // region taxonomy

$rd_terms = wp_get_post_terms( $post->ID, $rd_taxonomy, array( "fields" => "ids" ) ); // getting the term IDs

if( $rd_terms ) {

                $term_array = trim( implode( ',', (array) $rd_terms ), ' ,' );

                $neworderterms = get_terms($rd_taxonomy, 'orderby=none&include=' . $term_array );

                foreach( $neworderterms as $orderterm ) {

                                echo '<a href="' . get_term_link( $orderterm ) . '">' . $orderterm->name . '</a> » ';

                }

}

the_title(); echo '</div>';

Article by Diwakar Academy / WordPress Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Home
  • WordPress
  • About Us
  • Contact Us

Copyright © 2025 · All Rights Reserved · Terms and Conditions · Privacy Policy