Skip to content

Instantly share code, notes, and snippets.

@iladarsda
Created February 7, 2014 10:19
Show Gist options
  • Save iladarsda/8860227 to your computer and use it in GitHub Desktop.
Save iladarsda/8860227 to your computer and use it in GitHub Desktop.
WordPress: good breadcrumb example
<!-- BREADCRUMB -->
<?php if( function_exists('the_breadcrumbs') ) { ?>
<ol class='breadcrumb '>
<?php the_breadcrumbs(); ?>
</ol>
<?php } ?>
<!-- // BREADCRUMB -->
function the_breadcrumbs() {
global $post;
global $wp_query;
if ( ! is_home() ) {
echo "<li><a href='http://website.com/'>WebSite</a></li>";
echo "<li><a href='";
echo get_option('home');
echo "'>";
echo bloginfo('name');
echo "</a></li>";
if (is_category() || is_single()) {
//echo "<li>";
$cats = get_the_category( $post->ID );
//echo "</li>";
foreach ( $cats as $cat ){
//var_dump($cat);
echo "<li>";
echo "<a href='".get_category_link($cat->term_id)."'>".$cat->cat_name."</a>";
echo "</li>";
}
if ( is_single()) {
echo "<li>";
the_title();
echo "</li>";
}
} elseif (is_page()) {
$post = $wp_query->get_queried_object();
if ( $post->post_parent == 0 ){
echo "<li> ".the_title('','', FALSE)."</li>";
} else {
$title = the_title('','', FALSE);
$ancestors = array_reverse( get_post_ancestors( $post->ID ) );
array_push($ancestors, $post->ID);
foreach ( $ancestors as $ancestor ){
if( $ancestor != end($ancestors) ){
echo '<li><a href="'. get_permalink($ancestor) .'">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</a></li>';
} else {
echo '<li>'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</li>';
}
}
}
}
}
elseif (is_tag()) { single_tag_title(); }
elseif (is_day()) { echo"Archive: "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) { echo"Archive: "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) { echo"Archive: "; the_time('Y'); echo'</li>';}
elseif (is_author()) { echo"Author's archive: "; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "Blogarchive: "; echo'';}
elseif (is_search()) { echo"Search results: "; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment