I am working on a secret project [ ;) ] and decided that I'll use WordPress' internal categories and tags to group my products.
I didn't want to use an external plugin and here's the short snippet that I used in category.php
// because I am using the categories for categorizing the products.
// Goal: Home > WordPress > Plugins
if (is_category()) {
$sep = ' » ';
$home_page_link = "Home " . $sep;
$category = get_the_category();
$ID = $category[0]->cat_ID;
echo '' . $home_page_link . get_category_parents($ID, TRUE, $sep, FALSE ) . ' Showing Products' . '
';
}
If you want to build the breadcrumbs based on the currently requested category use this.
/if (is_category()) {
$cat = get_query_var('cat');
$current_cat = get_category($cat);
$links[] = "Home ";
if (!empty($current_cat->category_parent)) {
$parent_cat = get_category($current_cat->category_parent);
$parent_cat_link = get_category_link($current_cat->category_parent);
$links[] = "$parent_cat->cat_name";
}
$current_cat_link = get_category_link($current_cat->term_id);
$links[] = "$current_cat->cat_name";
//$links[] = "Showing Products";
$sep = ' » ';
echo '' . join($links, $sep) . '
';
}
Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer