ยป Download the Plugin | Support Forum
Genesis comes with two built-in navigation menus: Primary and Secondary. On most sites people only use the Primary and list subpages as a dropdown. But this plugin allows the secondary menu to be auto-populated with the current section's children pages.
So if you have a site structure like this:
- Home
- About
- About Our Team
- About Our Company
- Company History
- Contact
The Home and Contact pages will not show a secondary menu. If you are on About, About Our Company, About Our Team, or Company History it will show the secondary navigation (Company History will be a dropdown under About Our Company).
I've used this on a few projects so thought I'd turn it into a plugin. I plan to be sharing a lot more little bits of functionality as plugins rather than tutorials so that I can improve it even when I'm done with the client's website.
For advanced users, there's a filter that let's you modify the arguments that are passed to wp_list_pages. If you don't want any dropdowns coming off the secondary menu, you could do this:
/**
* Limit Subnav to one level
*
* @author Bill Erickson
* @link https://www.billerickson.net/genesis-subpages-as-secondary-menu
*
*/
add_filter('be_genesis_subpages_args', 'be_filter_subpages');
function be_filter_subpages($args){
$additions = array( 'depth' => '1');
return array_merge( $args, $additions );
} One client wanted the secondary nav to only show secondary pages (using the above code), and a third nav to show up if there's tertiary pages. Here's how to add a third navigation:
/**
* Add Third Navigation
*
* @author Bill Erickson
* @link https://www.billerickson.net/genesis-subpages-as-secondary-menu
*
*/
add_action('genesis_after_header', 'be_third_nav');
function be_third_nav() {
if( is_page() ) {
// Set standard args
$args = array(
'title_li' => '',
'echo' => false,
'depth' => '1'
);
// Get current location
wp_reset_query();
global $post;
// Don't run on top level page
if( empty( $post->post_parent ) )
return;
$parent = get_post( $post->post_parent );
// If on a secondary page, get children of current page
if ( empty( $parent->post_parent ) )
$args['child_of'] = $post->ID;
// If on tertiary page, get children of parent
else
$args['child_of'] = $parent->ID;
// Build menu
$menu = wp_list_pages( $args );
if ( !empty( $menu ) ) echo '<div id="thirdnav"><div class="wrap">'.$menu.'</div></div>';
}
}
No comments yet