Mangcoding

icon chat
Mulida Asti - Wednesday, 5 March 2025 - 4 months ago

Taxonomy Terms in Breadcrumbs

single image
Photo by Susanne Jutzeler on Pexels

TTaxonomy is part of the content grouping mechanism. Simply put, taxonomy allows you to group posts based on the same characteristics. In this tutorial, Mangcoding will share about Taxonomy Terms in Breadcrumbs, so let’s jump into the tutorial.

There are three different options in Taxonomy, including:

  • If the taxonomy is non-hierarchical
  • If the taxonomy is hierarchical but only one taxonomy term can be checked in the post
  • If the taxonomy is hierarchical and all terms can be checked in the post

Link Mangcoding

Non-hierarchical Taxonomy

This type of taxonomy works like post tags. The simplest way to print term links is using the the_terms() function.

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: ', ' / ' );

Link Mangcoding

Taxonomy with Hierarchical Levels

This taxonomy works like categories and is divided into two parts: When only one term is checked (selected), when all hierarchical levels are selected

1. Only one term is checked (selected)

Please refer to the previous code that Mangcoding explained above, the the_terms() function works perfectly for this.

2. When all hierarchical terms are selected**
To clarify, take a look at the display below!

Hierarki Mangcoding

Additionally, try to observe the following code, as the order of the terms will be very important in this case

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>';

That’s the article Mangcoding shared. Hopefully, this article is useful and provides new knowledge for you. If you have any constructive criticism or suggestions, feel free to comment or send them via Email and Mangcoding’s social media.

Reference : Rudrastyh.com

Link Copied to Clipboard