adding nav menu
authorIan Weller <ian@gaslightmedia.com>
Thu, 13 Nov 2014 17:17:00 +0000 (12:17 -0500)
committerIan Weller <ian@gaslightmedia.com>
Thu, 13 Nov 2014 17:17:00 +0000 (12:17 -0500)
functions.php
header.php
library/navigation.php [new file with mode: 0644]
library/top-bar_walker.php [new file with mode: 0644]

index 12d4aea..18b3851 100755 (executable)
@@ -3,5 +3,29 @@ function register_my_menu() {
   register_nav_menu('header-menu',__( 'Header Menu' ));
 }
 add_action( 'init', 'register_my_menu' );
+/**
+ * Left top bar
+ * http://codex.wordpress.org/Function_Reference/wp_nav_menu
+ */
+if ( ! function_exists( 'foundationPress_top_bar_l' ) ) {
+       function foundationPress_top_bar_l() {
+           wp_nav_menu(array( 
+               'container' => false,                           // remove nav container
+               'container_class' => '',                        // class of container
+               'menu' => '',                                   // menu name
+               'menu_class' => 'top-bar-menu left',            // adding custom nav class
+               'theme_location' => 'top-bar-l',                // where it's located in the theme
+               'before' => '',                                 // before each link <a> 
+               'after' => '',                                  // after each link </a>
+               'link_before' => '',                            // before each link text
+               'link_after' => '',                             // after each link text
+               'depth' => 5,                                   // limit the depth of the nav
+               'fallback_cb' => false,                         // fallback function (see below)
+               'walker' => new top_bar_walker()
+           ));
+       }
+}
 
+// Add menu walker
+require_once('library/top-bar_walker.php');
 ?>
\ No newline at end of file
index 66a6ea5..60a16ce 100644 (file)
         <div class="large-12 text-center columns">
             <nav class="top-bar" data-topbar role="navigation">
             <section class="top-bar-section">
-                <ul>
-                    <?php
-                    wp_nav_menu(array(
-                        'menu'    => 2, //menu id
-                        'walker'  => new Walker_Custom_Menu() //use our custom walker
-                    ));
-                    ?>
-                </ul>
+                                    <?php foundationPress_top_bar_l(); ?>
+
             </section>
             </nav>
         </div>
             </ul>
         </aside>
     </header>
-    <div id="panel">
-    <div class="row">
-        <div class="small-12 columns">
-            <img id="slider" src="<?php echo get_template_directory_uri(); ?>/assets/slider_still.png">
-            <div id="overlay" class="small-11 medium-7 large-5 right columns">
-            <h2>Kitchen & Bath</h2>
-            <p>sam nos si dessus aciendes nis nos si deaciendes.</p>
-            </div>
-        </div>
-    </div>
-    <div class="row">
-        <div class="small-10 small-centered columns">
-            <h1 id="pan-text">Helping You Build With Confidence Since 1915</h1>
-        </div>
-    </div>
-    </div>
+    
diff --git a/library/navigation.php b/library/navigation.php
new file mode 100644 (file)
index 0000000..05aff31
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+
+/**
+ * Register Menus
+ * http://codex.wordpress.org/Function_Reference/register_nav_menus#Examples
+ */
+register_nav_menus(array(
+    'top-bar-l' => 'Left Top Bar', // registers the menu in the WordPress admin menu editor
+    'top-bar-r' => 'Right Top Bar',
+    'mobile-off-canvas' => 'Mobile'
+));
+
+
+/**
+ * Left top bar
+ * http://codex.wordpress.org/Function_Reference/wp_nav_menu
+ */
+if ( ! function_exists( 'foundationPress_top_bar_l' ) ) {
+       function foundationPress_top_bar_l() {
+           wp_nav_menu(array( 
+               'container' => false,                           // remove nav container
+               'container_class' => '',                        // class of container
+               'menu' => '',                                   // menu name
+               'menu_class' => 'top-bar-menu left',            // adding custom nav class
+               'theme_location' => 'top-bar-l',                // where it's located in the theme
+               'before' => '',                                 // before each link <a> 
+               'after' => '',                                  // after each link </a>
+               'link_before' => '',                            // before each link text
+               'link_after' => '',                             // after each link text
+               'depth' => 5,                                   // limit the depth of the nav
+               'fallback_cb' => false,                         // fallback function (see below)
+               'walker' => new top_bar_walker()
+           ));
+       }
+}
+
+/**
+ * Right top bar
+ */
+if ( ! function_exists( 'foundationPress_top_bar_r' ) ) {
+       function foundationPress_top_bar_r() {
+           wp_nav_menu(array( 
+               'container' => false,                           // remove nav container
+               'container_class' => '',                        // class of container
+               'menu' => '',                                   // menu name
+               'menu_class' => 'top-bar-menu right',           // adding custom nav class
+               'theme_location' => 'top-bar-r',                // where it's located in the theme
+               'before' => '',                                 // before each link <a> 
+               'after' => '',                                  // after each link </a>
+               'link_before' => '',                            // before each link text
+               'link_after' => '',                             // after each link text
+               'depth' => 5,                                   // limit the depth of the nav
+               'fallback_cb' => false,                         // fallback function (see below)
+               'walker' => new top_bar_walker()
+           ));
+       }
+}
+
+/**
+ * Mobile off-canvas
+ */
+if ( ! function_exists( 'foundationPress_mobile_off_canvas' ) ) {
+       function foundationPress_mobile_off_canvas() {
+           wp_nav_menu(array( 
+               'container' => false,                           // remove nav container
+               'container_class' => '',                        // class of container
+               'menu' => '',                                   // menu name
+               'menu_class' => 'off-canvas-list',              // adding custom nav class
+               'theme_location' => 'mobile-off-canvas',        // where it's located in the theme
+               'before' => '',                                 // before each link <a> 
+               'after' => '',                                  // after each link </a>
+               'link_before' => '',                            // before each link text
+               'link_after' => '',                             // after each link text
+               'depth' => 5,                                   // limit the depth of the nav
+               'fallback_cb' => false,                         // fallback function (see below)
+               'walker' => new top_bar_walker()
+           ));
+       }
+}
+
+/** 
+ * Add support for buttons in the top-bar menu: 
+ * 1) In WordPress admin, go to Apperance -> Menus. 
+ * 2) Click 'Screen Options' from the top panel and enable 'CSS CLasses' and 'Link Relationship (XFN)'
+ * 3) On your menu item, type 'has-form' in the CSS-classes field. Type 'button' in the XFN field
+ * 4) Save Menu. Your menu item will now appear as a button in your top-menu
+*/
+if ( ! function_exists( 'add_menuclass') ) {
+       function add_menuclass($ulclass) {
+           $find = array('/<a rel="button"/', '/<a title=".*?" rel="button"/');
+           $replace = array('<a rel="button" class="button"', '<a rel="button" class="button"');
+           
+           return preg_replace($find, $replace, $ulclass, 1);
+       }
+       add_filter('wp_nav_menu','add_menuclass');
+}
+
+?>
diff --git a/library/top-bar_walker.php b/library/top-bar_walker.php
new file mode 100644 (file)
index 0000000..8218dd5
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Customize the output of menus for Foundation top bar
+ */
+
+class top_bar_walker extends Walker_Nav_Menu {
+
+    function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
+        $element->has_children = !empty( $children_elements[$element->ID] );
+        $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : '';
+        $element->classes[] = ( $element->has_children && $max_depth !== 1 ) ? 'has-dropdown' : '';
+        
+        parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
+    }
+    
+    function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
+        $item_html = '';
+        parent::start_el( $item_html, $object, $depth, $args ); 
+        
+        $output .= ( $depth == 0 ) ? '<li class="divider"></li>' : '';
+        
+        $classes = empty( $object->classes ) ? array() : (array) $object->classes;  
+        
+        if( in_array('label', $classes) ) {
+            $output .= '<li class="divider"></li>';
+            $item_html = preg_replace( '/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html );
+        }
+        
+    if ( in_array('divider', $classes) ) {
+        $item_html = preg_replace( '/<a[^>]*>( .* )<\/a>/iU', '', $item_html );
+    }
+        
+        $output .= $item_html;
+    }
+    
+    function start_lvl( &$output, $depth = 0, $args = array() ) {
+        $output .= "\n<ul class=\"sub-menu dropdown\">\n";
+    }
+    
+}
+?>
\ No newline at end of file