Last active
December 28, 2015 01:49
-
-
Save andrewlaskey/7423349 to your computer and use it in GitHub Desktop.
Wordpress Breadcrumbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Test if the page is a parent or a child | |
// http://css-tricks.com/snippets/wordpress/if-page-is-parent-or-child/#comment-85846 | |
function is_tree($pid) | |
{ | |
global $post; | |
$ancestors = get_post_ancestors($post->$pid); | |
$root = count($ancestors) - 1; | |
$parent = $ancestors[$root]; | |
if(is_page() && (is_page($pid) || $post->post_parent == $pid || in_array($pid, $ancestors))) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
}; | |
// Output the breadcrumb | |
// Modified from http://cazue.com/articles/wordpress-creating-breadcrumbs-without-a-plugin-2013 | |
function the_breadcrumb() { | |
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>'; | |
echo '<li><a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></li>'; | |
} | |
} elseif (is_page()) { | |
if( is_tree($post->ID)){ | |
$anc = get_post_ancestors( $post->ID ); | |
foreach ( $anc as $ancestor ) { | |
$output = '<li><a href="'.get_permalink($ancestor).'" title="'.get_the_title($ancestor).'">'.get_the_title($ancestor).'</a></li>'; | |
} | |
echo $output; | |
} | |
echo '<li><a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></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>'; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row"> | |
<div class="large-12 columns"> | |
<?php the_breadcrumb(); ?> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment