Skip to content

Instantly share code, notes, and snippets.

@barbwiredmedia
Created October 18, 2013 22:29
Show Gist options
  • Save barbwiredmedia/7049178 to your computer and use it in GitHub Desktop.
Save barbwiredmedia/7049178 to your computer and use it in GitHub Desktop.
Wordress - Functions :Creating breadcrumbs listing pages post parents and children
//Bread crumbs created
function wordpress_breadcrumbs() {
$delimiter = '|';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<div id="crumbs">';
global $post;
if ( is_page() && !$post->post_parent ) {
echo $currentBefore;
the_title();
echo $currentAfter; }
elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $currentBefore;
the_title();
echo $currentAfter;
}
echo '</div>';
}
}
<?php wordpress_breadcrumbs(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment