Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think I had a similar desire as you to select and only show a sub menu being just the children menu items from an existing wordpress menu. This can be done by editing the functions.php and adding a shortcode that has it's own walker class to target and display a submenu.</p> <h3>PHP code for "menu" shortcode and customized menu walker class (all goes in functions.php):</h3> <pre><code> //register menu shortcode add_shortcode('menu', 'shortcode_menu'); function shortcode_menu($args ) { //don't echo the ouput so we can return it $args['echo']=false; //in case menu isn't found display a message $args['fallback_cb']='shortcode_menu_fallback'; //check if showing a submenu, if so make sure everything is setup to do so if (isset($args['show_submenu']) &amp;&amp; !empty($args['show_submenu'])) { if (!isset($args['depth'])) { $args['depth']=1; } $args['walker']=new Sub_Menu_Walker_Nav_Menu(); } $menu=wp_nav_menu( $args ); return $menu; } //message to display if menu isn't found function shortcode_menu_fallback($args ) {return 'No menu selected.';} //special walker_nav_menu class to only display submenu //depth must be greater than 0 //show_submenu specifies submenu to display class Sub_Menu_Walker_Nav_Menu extends Walker_Nav_Menu { function display_element( $element, &amp;$children_elements, $max_depth, $depth=0, $args, &amp;$output ) { if ( !$element ) return; $id_field = $this-&gt;db_fields['id']; $displaythiselement=$depth!=0; if ($displaythiselement) { //display this element if ( is_array( $args[0] ) ) $args[0]['has_children'] = ! empty( $children_elements[$element-&gt;$id_field] ); $cb_args = array_merge( array(&amp;$output, $element, $depth), $args); call_user_func_array(array(&amp;$this, 'start_el'), $cb_args); } $id = $element-&gt;$id_field; if ( is_array( $args[0] ) ){ $show_submenu=$args[0]['show_submenu']; }else $show_submenu=$args[0]-&gt;show_submenu; // descend only when the depth is right and there are childrens for this element if ( ($max_depth == 0 || $max_depth &gt;= $depth+1 ) &amp;&amp; isset( $children_elements[$id]) &amp;&amp; $element-&gt;title==$show_submenu) { foreach( $children_elements[ $id ] as $child ){ if ( !isset($newlevel) ) { $newlevel = true; //start the child delimiter $cb_args = array_merge( array(&amp;$output, $depth), $args); call_user_func_array(array(&amp;$this, 'start_lvl'), $cb_args); } $this-&gt;display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output ); } unset( $children_elements[ $id ] ); } if ( isset($newlevel) &amp;&amp; $newlevel ){ //end the child delimiter $cb_args = array_merge( array(&amp;$output, $depth), $args); call_user_func_array(array(&amp;$this, 'end_lvl'), $cb_args); } if ($displaythiselement) { //end this element $cb_args = array_merge( array(&amp;$output, $element, $depth), $args); call_user_func_array(array(&amp;$this, 'end_el'), $cb_args); } } } </code></pre> <h3>Display a submenu titled "About" from the "Main" menu (capitalization matters):</h3> <pre><code>[menu menu='Main' show_submenu='About'] </code></pre> <h3>Display the full "Main" menu:</h3> <pre><code>[menu menu='Main'] </code></pre> <p>For further reading/reference see <a href="http://wordpress.org/support/topic/wp_nav_menu-list-only-2nd-level-separate-submenu/page/2" rel="nofollow">this wordpress question</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload