Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created August 7, 2013 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/52ea222beab1dc2f2aad to your computer and use it in GitHub Desktop.
Save billerickson/52ea222beab1dc2f2aad to your computer and use it in GitHub Desktop.
<?php
/**
* Vertical Breadcrumb
*
* @package BE_Genesis_Child
* @since 1.0.0
* @link https://github.com/billerickson/BE-Genesis-Child
* @author Bill Erickson <bill@billerickson.net>
* @copyright Copyright (c) 2011, Bill Erickson
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*
*/
echo '<div class="campl-tertiary-navigation"><ul class="campl-vertical-breadcrumb">';
// Homepage
echo '<li><a href="' . home_url() . '">' . get_bloginfo( 'name' ) . '<span class="campl-vertical-breadcrumb-indicator"></span></a></li>';
// Ancestors
$ancestors = array_reverse( get_post_ancestors( get_the_ID() ) );
foreach( $ancestors as $ancestor )
echo '<li><a href="' . get_permalink( $ancestor ) . '">' . get_the_title( $ancestor ) . '<span class="campl-vertical-breadcrumb-indicator"></span></a></li>';
echo '</ul>';
echo '<ul class="campl-vertical-breadcrumb-navigation">';
// Sibling, Current and Children
global $post;
$current = $post->ID;
if( 0 !== $post->post_parent ) {
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->post_parent,
'orderby' => 'menu_order',
'order' => 'ASC',
'no_found_rows' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
);
$siblings = new WP_Query( $args );
if( $siblings->have_posts() ): while( $siblings->have_posts() ): $siblings->the_post();
if( $current == get_the_ID() )
be_vertical_breadcrumb_current();
else
echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
endwhile; endif; wp_reset_postdata();
} else {
// Current and Children
be_vertical_breadcrumb_current();
}
echo '</ul></div>';
/**
* Current and Children
*
*/
function be_vertical_breadcrumb_current() {
// Current Page
echo '<li class="campl-selected"><a href="' . get_permalink() . '">' . get_the_title() . '</a>';
// Children Pages
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => get_the_ID(),
'orderby' => 'menu_order',
'order' => 'ASC',
'no_found_rows' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
);
$children = new WP_Query( $args );
if( $children->have_posts() ):
echo '<ul class="campl-vertical-breadcrumb-children">';
while( $children->have_posts() ): $children->the_post();
echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
endwhile;
echo '</ul>';
endif;
wp_reset_postdata();
echo '</li>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment