Guest User

Dan Fraticiu

a guest
Sep 12th, 2010
7,924
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Nfr_Menu_Walker extends Walker_Nav_Menu{
  4.  
  5.         /**
  6.      * Traverse elements to create list from elements.
  7.      *
  8.      * Display one element if the element doesn't have any children otherwise,
  9.      * display the element and its children. Will only traverse up to the max
  10.      * depth and no ignore elements under that depth. It is possible to set the
  11.      * max depth to include all depths, see walk() method.
  12.      *
  13.      * This method shouldn't be called directly, use the walk() method instead.
  14.      *
  15.      * @since 2.5.0
  16.      *
  17.      * @param object $element Data object
  18.      * @param array $children_elements List of elements to continue traversing.
  19.      * @param int $max_depth Max depth to traverse.
  20.      * @param int $depth Depth of current element.
  21.      * @param array $args
  22.      * @param string $output Passed by reference. Used to append additional content.
  23.      * @return null Null on failure with no changes to parameters.
  24.      */
  25.     function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
  26.  
  27.         if ( !$element )
  28.             return;
  29.  
  30.         $id_field = $this->db_fields['id'];
  31.  
  32.         //display this element
  33.         if ( is_array( $args[0] ) )
  34.             $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
  35.        
  36.         //Adds the 'parent' class to the current item if it has children       
  37.         if( ! empty( $children_elements[$element->$id_field] ) )
  38.             array_push($element->classes,'parent');
  39.        
  40.         $cb_args = array_merge( array(&$output, $element, $depth), $args);
  41.        
  42.         call_user_func_array(array(&$this, 'start_el'), $cb_args);
  43.  
  44.         $id = $element->$id_field;
  45.  
  46.         // descend only when the depth is right and there are childrens for this element
  47.         if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
  48.  
  49.             foreach( $children_elements[ $id ] as $child ){
  50.  
  51.                 if ( !isset($newlevel) ) {
  52.                     $newlevel = true;
  53.                     //start the child delimiter
  54.                     $cb_args = array_merge( array(&$output, $depth), $args);
  55.                     call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
  56.                 }
  57.                 $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
  58.             }
  59.             unset( $children_elements[ $id ] );
  60.         }
  61.  
  62.         if ( isset($newlevel) && $newlevel ){
  63.             //end the child delimiter
  64.             $cb_args = array_merge( array(&$output, $depth), $args);
  65.             call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
  66.         }
  67.  
  68.         //end this element
  69.         $cb_args = array_merge( array(&$output, $element, $depth), $args);
  70.         call_user_func_array(array(&$this, 'end_el'), $cb_args);
  71.     }
  72. }
RAW Paste Data