I'm currently using the code below to display my breadcrumbs. Which works fine up to a point. What I want is:
Home > Level 1 > Level 2 > Level 3
What I get is:
Home > Level 1 > Level 3
It's displaying one parent, so as long as your deepest link is a Level 2 you can't tell the difference. But you know, for complex sites that's just not enough.
Suggestions as to how to adjust this code to include all parents are most welcome.
The code:
function themename_breadcrumb() {
global $post;
echo '<ul class="breadcrumbs">';
if (!is_home()) {
echo '<li><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo "</a></li>";
if (is_category() || is_single()) {
echo '<li>';
the_category(' </li><li> ');
if (is_single()) {
echo "</li><li>";
the_title();
echo '</li>';
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$anc_link = get_page_link( $post->post_parent );
foreach ( $anc as $ancestor ) {
$output = "<li><a href=" . $anc_link . ">" . get_the_title( $ancestor ) . "</a>";
}
echo $output;
echo '</li><li> ';
echo the_title();
echo '</li>';
} else {
echo '</li><li> ';
echo the_title();
echo '</li>';
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ul>';
}