<?php | |
/** | |
* Vertical Breadcrumb | |
* | |
* @package BE_Genesis_Child | |
* @since 1.0.0 | |
* @link https://github.com/billerickson/BE-Genesis-Child | |
* @author Bill Erickson <[email protected]> | |
* @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>'; | |
} | |
Bill Erickson
Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.
Ready to upgrade your website?
I build custom WordPress websites that look great and are easy to manage.
Other articles in this series
Shortcode Finder
February 21, 2019
I’m cleaning up a website with a lot of old shortcodes. Before removing a shortcode, we wanted to be sure all pages that used it were updated. So I wrote a shortcode to help 🙂…
Building a Gutenberg website
February 18, 2019
Gutenberg is the new block-based content editor in WordPress. I’ll show you how to develop a Gutenberg-optimized WordPress theme and provide examples of client sites using Gutenberg.
Gutenberg Color Palette and Button Styling
February 18, 2019
A developer’s guide to creating a WordPress color palette and applying the styles to Gutenberg blocks.
Block Styles in Gutenberg
February 18, 2019
Every block type in the WordPress editor can have multiple style options. I’ll show you how to add and remove style options from blocks.