Walker_Nav_Menu menu

I have these code

<?php // Allow HTML descriptions in WordPress Menu remove_filter( 'nav_menu_description', 'strip_tags' ); function my_plugin_wp_setup_nav_menu_item( $menu_item ) {     if ( isset( $menu_item->post_type ) ) {         if ( 'nav_menu_item' == $menu_item->post_type ) {             $menu_item->description = apply_filters( 'nav_menu_description', $menu_item->post_content );         }     }     return $menu_item; } add_filter( 'wp_setup_nav_menu_item', 'my_plugin_wp_setup_nav_menu_item' ); class my_custom_walker_nav_menu extends Walker_Nav_Menu { public function display_element($el, &$children, $max_depth, $depth = 0, $args, &$output){     $id = $this->db_fields['id'];     if(isset($children[$el->$id])){         $el->classes[] = 'has_children';     }     parent::display_element($el, $children, $max_depth, $depth, $args, $output); } // add classes to ul sub-menus function start_lvl( &$output, $depth = 0, $args = array() ) {     // depth dependent classes     $indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' ); // code indent     $display_depth = ( $depth + 1); // because it counts the first submenu as 0     $classes = array(         'navi',         ( $display_depth ==1 ? 'first' : '' ),         ( $display_depth >=2 ? 'navi' : '' ),         'menu-depth-' . $display_depth         );     $class_names = implode( ' ', $classes );     // build html     $output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n"; } // add main/sub classes to li's and links  function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {     global $wp_query;     $indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent     static $is_first;     $is_first++;     // depth dependent classes     $depth_classes = array(         ( $depth == 0 ? 'main-menu-item' : '' ),         ( $depth >=2 ? 'navi' : '' ),         ( $is_first ==1 ? 'menu-first' : '' ),         'menu-item-depth-' . $depth     );     $depth_class_names = esc_attr( implode( ' ', $depth_classes ) );     // passed classes     $classes = empty( $item->classes ) ? array() : (array) $item->classes;     $class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) );     $post_meta_array = get_post_meta($item->ID);     $is_megamenu = $post_meta_array['_menu_item_megamenu'][0];     $is_mega_menu = ($is_megamenu !== '') ? true : false;     $use_desc = (strpos($class_names, 'use_desc') !== false) ? true : false;     $no_title = (strpos($class_names, 'no_title') !== false) ? true : false;     $is_sidebar = (strpos($class_names, 'menu_sidebar') !== false) ? true : false;     if(!$is_mega_menu){         $class_names .= ' normal_menu_item';     } else{         $class_names .= ' '.$is_megamenu;     }     // build html     $output .= $indent . '<li a id="nav-menu-item-'. $item->ID . '" class="' . $depth_class_names . ' ' . $class_names . '">';     // link attributes     $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';     $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';     $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';     $attributes .= ! empty( $item->url )        ? ' href="' . (($item->url[0] == "#" && !is_front_page()) ? esc_url(home_url('/')) : '') . esc_attr($item->url) .'"' : '';     $attributes .= ' class="menu-link '.((strpos($item->url,'#') === false) ? '' : 'scroll').' ' . ( $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ) . '"';     $html_output = ($use_desc) ? '<div class="description_menu_item">'.$item->description.'</div>' : '';     if ($is_sidebar) {         ob_start();         dynamic_sidebar($item->description);         $sidebar_html = ob_get_clean();         $sidebar_output = '<div class="sidebar_menu_item">'.$sidebar_html.'</div>';         $item_output = $sidebar_output;     } else{         $item_output = (!$no_title) ? '<a ' . $attributes . '><span>' . apply_filters( 'the_title', $item->title, $item->ID ) . '</span></a>'. $html_output : $html_output;     }     // build html     $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ).( ($is_mega_menu) ? '<div class="sf-mega"><div class="sf-mega-inner clearfix">':''); } function end_el( &$output, $item, $depth = 0, $args = array() ) {     $classes = empty( $item->classes ) ? array() : (array) $item->classes;     $class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) );     $is_mega_menu = (strpos($class_names,'mega') !== false) ? true : false;     $output .= (($is_mega_menu)?'</div></div>':'') . "</li>\n"; } } // Megamenu in menu. Modified original file by Weston Ruter on https://gist.github.com/westonruter/3802459 add_action( 'init', array( 'my_custom_Nav_Menu_Item_Custom_Fields', 'setup' ) ); class my_custom_Nav_Menu_Item_Custom_Fields {     static $options = array(             'item' => '                 <div class="additional-menu-field-{name} {container_class}">                 <style scoped>                     .additional-menu-field-megamenu{display:inline-block;}                 </style>                     <label for="edit-menu-item-{name}-{id}">{label}</label>                     <div class="megamenu">                         <select name="{name}" id="select-mega-menu-{id}">                             <option value="">Default Standard Menu</option>                             <option value="{mega1}">Mega Menu - Single Column</option>                             <option value="{mega2}">Mega Menu - 2 Columns</option>                             <option value="{mega3}">Mega Menu - 3 Columns</option>                             <option value="{mega4}">Mega Menu - 4 Columns</option>                             <option value="{mega5}">Mega Menu - 5 Columns</option>                             <option value="{mega6}">Mega Menu - 6 Columns</option>                             <option value="{mega7}">Mega Menu - 7 Columns</option>                         </select>                         <input type="{input_type}" id="edit-menu-item-{name}-{id}" class="widefat code edit-menu-item-{name}" name="menu-item-{name}[{id}]" value="{value}">                     </div>                 </div>             ',         );     static function setup() {         self::$options['fields'] = array(             'megamenu' => array(                 'name'            => 'megamenu',                 'label'           => esc_html__('Mega Menu', 'my_custom'),                 'container_class' => 'menu-megamenu',                 'input_type'      => 'hidden',             ),         );         add_filter( 'wp_edit_nav_menu_walker', function () {             return 'my_custom_Walker_Nav_Menu_Edit';         });         add_filter( 'my_custom_nav_menu_item_additional_fields', array( __CLASS__, '_add_fields' ), 10, 5 );         add_action( 'save_post', array( __CLASS__, '_save_post' ) );     }     static function get_fields_schema() {         $schema = array();         foreach(self::$options['fields'] as $name => $field) {             if (empty($field['name'])) {                 $field['name'] = $name;             }             $schema[] = $field;         }         return $schema;     }     static function get_menu_item_postmeta_key($name) {         return '_menu_item_' . $name;     }     /**      * Inject the      * @hook {action} save_post      */     static function _add_fields($new_fields, $item_output, $item, $depth, $args) {         $schema = self::get_fields_schema($item->ID);         foreach($schema as $field) {             $field['value'] = get_post_meta($item->ID, self::get_menu_item_postmeta_key($field['name']), true);             $field['id'] = $item->ID;             //Tried to implement selected() here but was unsuccesfull, so I just left it like this, the mega fields aren't necessary, you can add them by hand             $field['mega1'] = 'mega1';             $field['mega2'] = 'mega2';             $field['mega3'] = 'mega3';             $field['mega4'] = 'mega4';             $field['mega5'] = 'mega5';             $field['mega6'] = 'mega6';             $field['mega7'] = 'mega7';             $new_fields .= str_replace(                 array_map(function($key){ return '{' . $key . '}'; }, array_keys($field)),                 array_values(array_map('esc_attr', $field)),                 self::$options['item']             );         }         return $new_fields;     }     /**      * Save the newly submitted fields      * @hook {action} save_post      */     static function _save_post($post_id) {         if (get_post_type($post_id) !== 'nav_menu_item') {             return;         }         $fields_schema = self::get_fields_schema($post_id);         foreach($fields_schema as $field_schema) {             $form_field_name = 'menu-item-' . $field_schema['name'];             if (isset($_POST[$form_field_name][$post_id])) {                 $key = self::get_menu_item_postmeta_key($field_schema['name']);                 $value = stripslashes($_POST[$form_field_name][$post_id]);                 update_post_meta($post_id, $key, $value);             }         }     } } require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; class my_custom_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {     function start_el(&$output, $item, $depth, $args) {         $item_output = '';         parent::start_el($item_output, $item, $depth, $args);         $new_fields = apply_filters( 'my_custom_nav_menu_item_additional_fields', '', $item_output, $item, $depth, $args );         // Inject $new_fields before: <div class="menu-item-actions description-wide submitbox">         if ($new_fields) {             $item_output = preg_replace('/(?=<div[^>]+class="[^"]*submitbox)/', $new_fields, $item_output);         }         $output .= $item_output;     } } //Sidebars in Menu if ( !class_exists('sidebars_custom_menu')) {     class sidebars_custom_menu {         public function add_nav_menu_meta_boxes() {             add_meta_box(                 'sidebar_menu_add',                 esc_html__('Add Sidebar', 'my_custom'),                 array( $this, 'nav_menu_link'),                 'nav-menus',                 'side',                 'low'             );         }         public function nav_menu_link() {?>             <div id="posttype-sidebars" class="posttypediv">                 <div id="tabs-panel-sidebars" class="tabs-panel tabs-panel-active">                     <ul id ="sidebars-checklist" class="categorychecklist form-no-clear">                         <?php                         $i = -1;                         foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) {                             ob_start();                             dynamic_sidebar($sidebar['id']);                             $sidebar_html = ob_get_clean();                             ?>                             <li>                                 <label class="menu-item-title">                                     <input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-object-id]" value="<?php echo $sidebar['id']; ?>"> <?php echo ucwords( $sidebar['name'] ); ?>                                 </label>                                 <input type="hidden" class="menu-item-type" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-type]" value="custom">                                 <input type="hidden" class="menu-item-attr-title" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-attr-title]" value="<?php echo ucwords( $sidebar['name'] ); ?>">                                 <input type="hidden" class="menu-item-title" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-title]" value="&nbsp;" />                                 <input type="hidden" class="menu-item-url" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-url]" value="">                                 <input type="hidden" class="menu-item-classes" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-classes]" value="menu_sidebar">                                 <input type="hidden" class="menu-item-description" name="menu-item[<?php echo esc_attr($i); ?>][menu-item-description]" value="<?php echo $sidebar['id']; ?>">                             </li>                             <?php                             $i --;                         }                         ?>                     </ul>                 </div>                 <p class="button-controls">                     <span class="list-controls">                         <a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&amp;selectall=1#posttype-sidebars' ); ?>" class="select-all"><?php esc_html_e('Select All', 'my_custom'); ?></a>                     </span>                     <span class="add-to-menu">                         <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_html_e('Add to Menu', 'my_custom');?>" name="add-post-type-menu-item" id="submit-posttype-sidebars">                         <span class="spinner"></span>                     </span>                 </p>             </div>         <?php }     } } $custom_nav = new sidebars_custom_menu; add_action('admin_init', array($custom_nav, 'add_nav_menu_meta_boxes')); 

to have a mega menu in wordpress. The probleme is that it gives me an error like this Strict Standards: Declaration of my_custom_Walker_Nav_Menu_Edit::start_el() should be compatible with Walker_Nav_Menu_Edit::start_el(&$output, $item, $depth = 0, $args = Array, $id = 0) i've try to change function start_el(&$output, $item, $depth, $args)

to

function start_lvl( &$output, $item, $depth = 0, $args = array() ) without effect

Replay

Category: wordpress Time: 2016-07-28 Views: 0

Related post

  • Walker_Nav_menu access parent menu name 2014-04-09

    I extended Walker_Nav_Menu with the code below and I would like to replace [TITLE HERE] with the name of the parent menu... In my menu I only display one depth of the navigation at a time. So I would like to display the name of the submenu's parent.

  • Can't add optional class to menu item when using Walker_Nav_Menu 2015-01-23

    As a wordpress beginner. I'm creating menu also want to customized the <li> tag to be able to assign different class name to control specific behavior through CSS so I use custom walker to get a list with clean markup that I found here: https://gist

  • Trouble adding arbitrary menu items to Walker_Nav_Menu 2015-03-03

    I am trying to manually add two items to my menu because I want them to be (linked) images, and I don't believe there's a way to do that without some custom code. Going off the instructions in This answer, since my case was a little different, I adde

  • Walker_Nav_Menu check if menu has parent 2015-03-29

    I created a custom function extending Walker Menu and having some few issues. I got a post from https://wordpress.org/support/topic/how-do-i-know-if-a-menu-item-has-children-or-is-a-leaf showing me how to know if item has children with this code. $pa

  • Display a portion/ branch of the menu tree using wp_nav_menu() 2010-10-11

    I have a menu defined in WP Admin that looks like this: I want to be able to display all the child links on the sidebar whenever I am at a parent page. For example, if the user is on my "About Us" page, I want a list of the 4 links highlighted i

  • Add Class to Specific Link in Custom Menu 2011-02-22

    I know you can add a class in the custom menu options, but it adds it to the LI before the A. I want to apply the class directly to this specific A rather then the whole LI. So instead of the output being <li id="menu-item-51" class="NEW

  • Adding custom post type archives to a WordPress menu 2011-02-25

    Is there a way (besides adding a Custom Link) to add a custom post type archive to a menu in WordPress? If it's added using a custom link (e.g. /cpt-archive-slug/), WordPress does not apply classes like current-menu-item to the list element, which pr

  • How to add a Custom Link to a Menu with an URL that is relative to the blog URL 2011-03-11

    Part of my work is to create Wordpress websites. I usually work on my laptop until I have something good enough to be uploaded to the test server where the client reviews it. I create a VirtualHost for every new project so I'm always working with a W

  • Get the ID of the page a menu item links to? 2011-03-31

    I am currently using a custom walker to customize the output of wp_nav_menu(), and I am trying to add additional information to the <a> tags. What I want the output for each menu link to look like is: <a class="boxPAGEID" href="#&q

  • Menu items description? Custom Walker for wp_nav_menu() 2011-04-05

    Normal Wordpress Menu looks like: Home | Blog | About us | Contact But I've seen many pages with descriptions under these links: Home Page | Our Blogs | About us | Contact ....meet us...| read more| basic info| contact form How to achieve this? (I wa

  • How do I add the menu item description to the menu? 2011-04-05

    Normal Wordpress Menu looks like: Home | Blog | About us | Contact But I've seen many pages with descriptions under these links: Home Page | Our Blogs | About us | Contact ....meet us...| read more| basic info| contact form How to achieve this? (I wa

  • Display navigation menu item conditionally based on user capabilities 2011-04-07

    I have one "branch" of my main site's navigation tree that should only be accessible to a set of registered, logged-in users. I understand how to query a user's role and capabilities. This question is specifically about what is the best way to l

  • wordpress custom walker for thumbnails with custom menu 2011-05-01

    I'm still very novice at PHP so any help is greatly appreciated. Typically I have found the codex to be very helpful but it appears custom walkers may be outside its scope. I'd like to have thumbnails show in a custom nav menu which I have in a theme

  • Add 'has_children' class to parent li when modifying Walker_Nav_Menu 2011-05-10

    I'm writing a customised walker class for wp_nav_menu and want to be able to specify if an li contains a submenu. So I want my markup to be: <li class="has_children [other-wordpress-classes]"> <a class="parent-link">Some it

  • Show All Children of WordPress Menu 2011-05-20

    The code below shows the active sub menu of the Main Menu. It's nearly perfect, however, I need it to show ALL subitems of these sub items, and their children. AKA unlimited depth. Thanks in advance! To further clarify here is an example: WP - Main M

  • HTTPS page link in menu 2011-05-25

    Ok, so I have a wordpress site with a lot of pages and menus that I've defined in the appearance/menus section of wordpress. One of my pages has a little payment form on, which I'd like to link to with https://blahlbah.com/thepage.. and for all the o

  • Replacing WordPress menu functionality with a plugin 2011-07-28

    I asked this earlier on StackOverflow.com before realizing there was a StackExchange specifically for WordPress. Here is the link to the old question (for moderator deletion): http://stackoverflow.com/questions/6862887/replacing-wordpress-core-functi

  • Bar separated navigation by extending Walker_Nav_Menu 2011-08-23

    I have the following menu in my header: <?php $args = array( 'menu' => 'Main Menu', 'container' => false, 'depth' => 1, 'items_wrap' => '%3$s', 'walker' => new Bar_List_Walker_Nav_Menu ); wp_nav_menu($args); ?> and I want to make the

  • Add Caret to Menu Items with Sub-Menus in WordPress Theme 2011-08-25

    I'm working on a custom theme using wp_nav_menu(). What I want to do is add a caret to menu items that have sub-menus. For example, If my menu looks like this: Menu Item 1 Menu Item 2 Menu Item 2a Menu Item 2b Menu Item 3 I want to be able to format

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.707 (s). 13 q(s)