Make BreadCrumbs In WordPress Categories

As all of us knows what breadcrumbs are but i’m defining it again for the beginners.
Breadcrumbs are the subcategories structure that tells you in which category and subcategories you are standing right now. Just like you can see it in this link click here.
You can see a line like that

Phones > Mobile Phones > Smartphones > Samsung


This is the breadcrumb that we are talking about.
In WordPress we make categories , and then their subcategories if you wan’t to get all of your categories breadcrumbs then this post is dedicated to you.
We will make breadcrumbs of WordPress database. Here is the code below to make it.

Example:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "wordpress_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT term_id, parent  FROM wp_term_taxonomy";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {

        $pw_cat_name=$row["term_id"];
		
		$sql4 = "SELECT name FROM wp_terms where term_id=" . $row["term_id"];
		$result4 = $conn->query($sql4);
		$row4 = $result4->fetch_assoc();
		
		$pw_cat_name=$row4["name"];
        $pw_cat_pid=$row["parent"];


 
        if($pw_cat_pid >0){
while($pw_cat_pid != 0) {
    $sql2 = "SELECT term_id, parent  FROM wp_term_taxonomy where term_id=" . $pw_cat_pid;
    $result2 = $conn->query($sql2);
    $row2 = $result2->fetch_assoc();
	
	$sql3 = "SELECT name FROM wp_terms where term_id=" . $row2["term_id"];
    $result3 = $conn->query($sql3);
    $row3 = $result3->fetch_assoc();
	
	$pw_cat_name =  $row3["name"].'>' .$pw_cat_name;
    $pw_cat_pid = $row2["parent"];
}

            echo $pw_cat_name.'<br/>';
        }
}
} else {
    echo "0 results";
}
$conn->close();
?>

Output:

phone > smartphone > samsung
tv&led > samsung
computers > laptop > dell

This code will make breadcrumbs for all your categories and sub categories. Just make this code compatible to your code like database table names etc. This is how you can print all your breadcrumbs of WordPress database.