Skip to content

Instantly share code, notes, and snippets.

@rileypaulsen
Created August 3, 2013 13:51
Show Gist options
  • Save rileypaulsen/6146531 to your computer and use it in GitHub Desktop.
Save rileypaulsen/6146531 to your computer and use it in GitHub Desktop.
display a breadcrumb trail of page ancestors, with alternative cases for custom post types
<?php
$type = get_post_type();
$ancestors = array_reverse(get_post_ancestors($post->ID));
if( $type == 'page' ) : ?>
<nav id="breadcrumbs">
<ul>
<?php foreach($ancestors as $ancestor): ?>
<li><a href="<?php echo get_permalink($ancestor); ?>"><?php echo get_the_title($ancestor); ?></a></li>
<?php endforeach ?>
<li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li>
</ul>
</nav>
<?php elseif( $type == 'journal' ): ?>
<nav id="breadcrumbs">
<ul>
<li><a href="<?php echo get_permalink(PageIDs::resources); ?>">Resources</a></li>
<li><a href="<?php echo get_permalink(443); ?>">Learning Cultures Journal</a></li>
<li><a href="<?php echo get_term_link(43,'journal_issue'); ?>"><?php echo '2012'; ?></a></li>
<li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo truncate_text($post->post_title,40); ?></a></li>
</ul>
</nav>
<?php elseif( $type == 'practitioner' ): ?>
<nav id="breadcrumbs">
<ul>
<li><a href="<?php echo get_permalink(PageIDs::practitioners); ?>">Practitioners</a></li>
<li><a href="<?php echo get_permalink(443); ?>">type</a></li>
<li><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></li>
</ul>
</nav>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment