// Register menus region
//
if ( function_exists( 'register_nav_menus' ) ) {
register_nav_menus(
'top-menu' => __('Top Menu',EWF_SETUP_THEME_DOMAIN),
)
);
}
// Attach menu action
//
add_action('ewf-menu-top', 'ewf_action_menuTopInstall');
// To use it anyware on template add
// do_action('ewf-menu-top');
// Attach menu on region
//
function ewf_action_menuTopInstall(){
$ewf_menu_registred = has_nav_menu('top-menu');
$ewf_menu_walker = new EWF_Walker_Nav_Frontend;
if($ewf_menu_registred){
'theme_location' => 'top-menu',
'container_class' => null,
'container' => null,
'menu_id' => 'menu',
'class' => null,
'walker' => $ewf_menu_walker,
'menu_class' => 'sf-menu fixed' ));
}else{
echo '<p class="error-no-menu">'.__
('Menu not selected - Please review documentation!',EWF_SETUP_THEME_DOMAIN
).'</p>'; }
}
// Custom Walker to load menus with icons on Front End
//
class EWF_Walker_Nav_Frontend extends Walker_Nav_Menu {
var $ewf_mm_active = 0;
var $ewf_mm_columns = 0;
public function start_lvl
( &$output, $depth = 0
, $args = array() ) { $debug = ' data-mega="'.$this->ewf_mm_active.'" data-depth="'.$depth.'" ';
$debug = null;
if($this->ewf_mm_active && $depth === 0 ){
$output .= "\n$indent<div$debug class='sf-mega {ewf-mm-cols}'>\n"; // DIV
}else{
$output .= "\n$indent<ul$debug class='sub-menu'>\n";
}
}
public function end_lvl
(&$output, $depth = 0
, $args = array()) { $debug = ' data-mega="'.$this->ewf_mm_active.'" data-depth="'.$depth.'" ';
$debug = null;
if($this->ewf_mm_active && $depth === 0 ){
$output .= "</div>\n"; // DIV
$output = str_replace ('{ewf-mm-cols}', 'sf-mega-cols-'.$this->ewf_mm_columns, $output);
$this->ewf_mm_active = 0;
$this->ewf_mm_columns = 0;
}else{
$output .= $indent . "</ul>\n";
}
}
public function end_el
( &$output, $item, $depth = 0
, $args = array() ) {
if ($this->ewf_mm_active && $depth == 1){
$output .= "</div>\n";
}else{
$output .= $indent . "\n</li>\n";
}
}
public function start_el
( &$output, $item, $depth = 0
, $args = array(), $id = 0
) { $indent = ( $depth ) ?
str_repeat( "\t", $depth ) : '';
$extra_attr = null;
$item_output = null;
$current_url = strtolower($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$page_fields = get_post( $item->object_id);
$page_slug = $page_fields->post_name;
$classes[] = 'menu-item-' . $item->ID;
if ($item->mega_menu){
$this->ewf_mm_active = 1;
$classes['mega-menu'] = 'mega-menu';
if ($depth) $classes[] = 'sf-mega-section';
}
if ($item_url==$current_url){
$classes[] = 'current';
}
$class_names = join( ' ', apply_filters
( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
if ($this->ewf_mm_active && $depth == 1){
$this->ewf_mm_columns++;
$class_names = ' class="sf-mega-section" ';
$output .= $indent . '<div '.$extra_attr.$class_names.'>'."\n";
}else{
if (!$this->ewf_mm_active){
$class_names = str_replace('menu-item-has-children', 'menu-item-has-children dropdown', $class_names); }
$output .= $indent . '<li '.$extra_attr.$class_names.'>'."\n";
$attributes = ! empty( $item->title ) ?
' title="' . esc_attr
( $item->title ) .'"' : ''; $attributes .= ! empty( $item->target ) ?
' target="' . esc_attr
( $item->target ) .'"' : ''; $attributes .= ! empty( $item->url ) ?
' href="' . $item->url .'"' : '';
$item_output = $args->before;
$item_output .= $indent . '<a'. $attributes .' rel="page-'.$item->object_id.'" ><span>';
$item_output .= $args->link_before;
if ($item->icon){
$item_output .= '<i class="'.$item->icon.'"></i> ';
}
$item_output .= apply_filters( 'the_title', $item->title, $item->ID );
$item_output .= $args->link_after;
$item_output .= '</span></a>';
$item_output .= $args->after;
}
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}