Some themes or sites are well branched and navigation may go deeper than 2 levels only. In such cases building nested list of categories/subcategories (or pages/subpages) may look silly but in the same time 100% functional. Honestly, I’m not a fan of displaying mini site-map either in sidebar or drop-down so building sequential navigation in conjuction with breadcrumbs would be much more elegant solution.
I guess building sequential navigation will be the subject of another tutorial, right now we’ll stay focused on breadcrumbs only.
What are breadcrumbs? These are nothing but a road map of your site. They will help visitor to navigate easily and not allow to make him lost. Just take a look above the title of this article and everything will be clear enough.
<?php
//where are we now?
$categ_sp = get_the_category();
//are there any parent categories?
$my_parents = get_category_parents( $categ_sp[ 0 ]->cat_ID, TRUE, ',' );
$arr_parents = explode( ',', $my_parents );
//remove the last empty one if any
array_pop( $arr_parents );
if( count( $arr_parents ) > 1 ) {
echo '<div id="breadcrumbz">';
echo '<ul>';
echo '<li><a href="' . get_option( 'home' ) . '">Home</a> ></li>';
$x = 0;
while( $x < count( $arr_parents ) ) {
echo '<li>' . $arr_parents[ $x ] . ' ></li>';
$x ++;
}
//for a case we are currently reading single article display title, not as a link
if( is_single() ) echo '<li>' . get_the_title() . '</li>';
echo '</ul>';
echo '</div>';
}
?>