Skip to main content

WordPress: Foundation 6 Top-Menu

Foundation Walker

class FoundationMenu 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 ) ? '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.= "<ul class=\"menu vertical dropdown\" data-dropdown-menu>";
  }
}



Save this file as foundation-menu.php

functions.php

function foundation_menu_left()
{
  wp_nav_menu(array(
              'container' => false,
              'container_class' => '',
              'menu' => 'header-left',
              'theme_location' => 'header-left',
              'menu_class' => 'dropdown menu',
              'before' => '',
              'after' => '',
              'link_before' => '',
              'link_after' => '',
              'depth' => 0,
              'fallback_cb' => false,
              '$items_wrap' => '<ul class="menu vertical dropdown" >',
              'items_wrap' => '<ul id="%1$s" class="%2$s" data-dropdown-menu data-options="closingTime:50;alignment:right;">%3$s</ul>',
              'walker' => new FoundationMenu()
              )
  );
}

function foundation_menu_right()
{
  wp_nav_menu(array(
              'container' => false,
              'container_class' => '',
              'menu' => 'header-right',
              'theme_location' => 'header-right',
              'menu_class' => 'dropdown menu',
              'before' => '',
              'after' => '',
              'link_before' => '',
              'link_after' => '',
              'depth' => 0,
              'fallback_cb' => false,
              '$items_wrap' => '<ul class="menu vertical dropdown" >',
              'items_wrap' => '<ul id="%1$s" class="%2$s" data-dropdown-menu data-options="closingTime:50;alignment:right;">%3$s</ul>',
              'walker' => new FoundationMenu()
              )
  );
}
require_once get_template_directory().'/foundation-menu.php';

header.php

 <div class="top-bar">
    <div class="top-bar-title">
      <span data-responsive-toggle="responsive-menu" data-hide-for="medium">
        <span class="menu-icon" data-toggle></span>
      </span>
      <a href="<?= $url;?>"><strong>TITLE</strong></a>
    </div>
    <div id="responsive-menu">
     <div class="top-bar-left">
       <?php foundation_menu_left();?>
     </div>
     <div class="top-bar-right">
       <?php foundation_menu_right();?>
     </div>
   </div>
 </div>

Comments

Popular posts from this blog

WP similar or related posts widget without using any plugin

Hi guys, Recently I was working on some WP website and my client told me that he required a widget for displaying related/similar posts on the single post page. But as his website was already using many plugins, even for some pretty small tasks like this one, I decided not to use another WP plugin (plugins are not good for your WP websites, we will discuss about that on some other post.) I am not explaining the code as it is pretty simple if you are familiar with WP classes. But please let me know if you have any questions related to the PHP code posted below in the comments section or even much better, on Gist. You can add the following code directly in your child theme's functions.php file or you can create a separate file and include this at the bottom of functions.php file. <?php class similar_posts_widget extends WP_Widget {     function __construct()     {         parent::__construct('similar_posts_...

Java Program to display Welcome Message

import java.io.*;// I/O package imported. public class Welcome{        //class name is "Welcome"     public Welcome(){      //constructor declaired to print the message.         System.out.println("Welcome to Java Programming Language!");/* System.out.println is used for output. Welcome Message is written within " ".*/     }//display() closes here.     public static void main(String[] args){        //main() is declaired to declair an object in it.         Welcome obj=new Welcome();  //Object "Obj" is bean created.     }//main() closes. }//class "Welcome" ends here. Above program displays the message which is written by you in " ".  In programs "/*" and "*/" are use for multiple line comment(s) and "//" is use for single line comment. Code line "Welc...

Should javascript be enabled or disabled?

Javascript Javascript is the most popular client-end scripting language used by every website.  Javascript provides a way to create custom tools for the websites which are used to improve the overall site quality and UI (User Interface). It's also popular as it allow the audio and video streaming too. Google used the javascript to load the web page contents dynamically i.e., instead of redirecting the user to a new page or refreshing the same page, the contents are updated on the required parts on the web page. This dynamic content loading approach is known as AJAX which has now become much more popular as almost every website is using this, at least, to validate the form. Javascript vs No-Javascript Some people often disable the javascript from their browser settings. If you are one of them and think that javascript is a security threat, then, you are completely wrong. Javascript is a way to improve the website quality according to the client's machine and navigato...