Snippets

Rik Kendell Section submenu

Updated by Rik Kendell

File submenu.php Modified

  • Ignore whitespace
  • Hide word diff
-<?php // SUBMENU - active page's children (or siblings if on child page)
+<nav class="submenu">
+	<div class="wrapper">
+	    <?php // SUBMENU - active page's children (or siblings if on child page)
 
-// If no ancestors, use current page. Else use last ancestor
-$section_id = empty( $post->ancestors ) ? $post->ID : end( $post->ancestors );
+	    // If no ancestors, use current page. Else use last ancestor
+	    $section_id = empty( $post->ancestors ) ? $post->ID : end( $post->ancestors );
 
-// Get theme menu locations
-$locations = get_nav_menu_locations();
+	    // Get theme menu locations
+	    $locations = get_nav_menu_locations();
 
-// Navigation location/name
-$menu = wp_get_nav_menu_object( $locations[ 'main-menu' ] ); // ie 'main-menu' is our nav menu's name
+	    // Navigation location/name
+	    $menu = wp_get_nav_menu_object( $locations[ 'main-menu' ] ); // ie 'main-menu' is our nav menu's name
 
-// Submenu items of identified section
-$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'post_parent' => $section_id ) );
+	    // Submenu items of identified section
+	    $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'post_parent' => $section_id ) );
+		
+	    if( !empty( $menu_items ) ) :
 
-if( !empty( $menu_items ) ) : ?>
-    
-    <nav class="submenu">
-        <ul class="nav">
-            
-            <?php // Output menu items
-            foreach( $menu_items as $menu_item ) :
-                echo '<li><a href="' . $menu_item->url . '">' . $menu_item->title . '</a></li>';		   		
-            endforeach; ?>
-            
-        </ul>
-    </nav>
+	    	// Hamburger toggle ?>
+	    	<button class="hamburger hamburger--spin toggle-submenu" type="button" aria-label="Menu" aria-controls="navigation">
+		  		<span class="hamburger-box">
+		    		<span class="hamburger-inner"></span>
+		  		</span>
+			</button>
+	    	
+	    	<?php // Output menu items ?>
+		    <ul class="section-submenu container nav">
+			    <?php foreach( $menu_items as $menu_item ) : ?>
+			   		<li><a href="<?php echo $menu_item->url; ?>"><?php echo $menu_item->title; ?></a></li>
+			    <?php endforeach; ?>
+	    	</ul>	   		
 
-<?php endif; ?>	
+		<?php endif; ?>	
+	</div>
+</nav>
Created by Rik Kendell

File submenu.php Added

  • Ignore whitespace
  • Hide word diff
+<?php // SUBMENU - active page's children (or siblings if on child page)
+
+// If no ancestors, use current page. Else use last ancestor
+$section_id = empty( $post->ancestors ) ? $post->ID : end( $post->ancestors );
+
+// Get theme menu locations
+$locations = get_nav_menu_locations();
+
+// Navigation location/name
+$menu = wp_get_nav_menu_object( $locations[ 'main-menu' ] ); // ie 'main-menu' is our nav menu's name
+
+// Submenu items of identified section
+$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'post_parent' => $section_id ) );
+
+if( !empty( $menu_items ) ) : ?>
+    
+    <nav class="submenu">
+        <ul class="nav">
+            
+            <?php // Output menu items
+            foreach( $menu_items as $menu_item ) :
+                echo '<li><a href="' . $menu_item->url . '">' . $menu_item->title . '</a></li>';		   		
+            endforeach; ?>
+            
+        </ul>
+    </nav>
+
+<?php endif; ?>	
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.