mwdelaney / sage-wp-nav-submenu
Get submenu items from a WordPress menu based on parent or sibling
Installs: 5 371
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 1
Forks: 1
Open Issues: 2
Requires
- php: >=5.3.2
README
This package is based entirely on this code from levymetal.
The instructions below are also taken from levymetal's excellent documentation.
To install, run the following in your Sage9-based theme directory:
composer require "mwdelaney/sage-wp-nav-submenu"
Include the submenu arguemnts in your wp_nav_menu function:
wp_nav_menu( array( 'menu' => 'Menu Name', ... 'sub_menu' => true ) );
By default, if you have many nested levels, this code will filter the menu by the absolute top level parent. If you want the menu to drill down dynamically by filtering the menu based on the direct parent, pass a "direct_parent" => true
parameter to the wp_nav_menu
call.
wp_nav_menu( array( 'menu' => 'Menu Name', ... 'sub_menu' => true, 'direct_parent' => true ) );
If you want to include the parent/root element in the menu, you can pass in a "show_parent" => true
parameter to display the root level item.
wp_nav_menu( array( 'menu' => 'Menu Name', ... 'sub_menu' => true, 'show_parent' => true ) );
If you want to include the parent/root element in the menu even if it has no children, you can pass in a "show_parent_only" => true
parameter to display the root level item.
wp_nav_menu( array( 'menu' => 'Menu Name', ... 'sub_menu' => true, 'show_parent' => true, 'show_parent_only' => true ) );
Of course, you can continue to use the standard wp_nav_menu parameters as well. For example, if you want to limit the number of nested children being displayed, you can use the depth
parameter. Or of you don’t want the menu to be displayed, you can use the echo parameter.