Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. class FoundationPress_top_bar_walker_custom extends Walker_Nav_Menu {
  2.  
  3.  
  4. function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
  5.  
  6. $element->has_children = !empty( $children_elements[$element->ID] );
  7. $element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : '';
  8. $element->classes[] = ( $element->has_children && $max_depth !== 1 ) ? 'has-dropdown' : '';
  9.  
  10. parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
  11. }
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
  19.  
  20.  
  21. $item_html = '';
  22. parent::start_el( $item_html, $object, $depth, $args );
  23.  
  24. $classes = empty( $object->classes ) ? array() : (array) $object->classes;
  25.  
  26. //custom menu-item field with the use of a plugin
  27. $value = get_post_meta( $object->ID, $key, true );
  28.  
  29.  
  30. if( in_array('label', $classes) ) {
  31. $item_html = preg_replace( '/<a[^>]*>(.*)</a>/iU', '<label>$1</label>', $item_html );
  32. }
  33.  
  34. if($value[ 'menu-item-polyfield-menuitem-color' ]){
  35. $color = $value[ 'menu-item-polyfield-menuitem-color' ][0];
  36. $item_html = preg_replace('/(<ab[^><]*)>/i', '$1 style="background: #'.$color.'">', $item_html);
  37.  
  38. }
  39.  
  40. $output .= $item_html;
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. function start_lvl( &$output, $depth = 0, $args = array() ) {
  49. $output .= "n<ul class="sub-menu dropdown">n";
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement