Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. wp_nav_menu(
  2. array(
  3. "container" => "nav",
  4. "container_class" => "container",
  5. "container_id" => "nav",
  6. "fallback_cb" => false,
  7. "menu_class" => "six columns omega main-nav sf-menu",
  8. "theme_location" => "main-nav"
  9. )
  10. );
  11.  
  12. <li class="...">
  13. <a href="#"><span>01.</span>Home</a>
  14. </li>
  15. <li class="...">
  16. <a href="#"><span>02.</span>Services</a>
  17. </li>
  18. <li class="...">
  19. <a href="#"><span>03.</span>Portfolio</a>
  20. </li>
  21.  
  22. class Wpse8170_Menu_Walker extends Walker_Nav_Menu {
  23.  
  24. var $number = 1;
  25.  
  26. function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  27. $indent = ( $depth ) ? str_repeat( "t", $depth ) : '';
  28.  
  29. $class_names = $value = '';
  30.  
  31. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  32. $classes[] = 'menu-item-' . $item->ID;
  33.  
  34. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  35. $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
  36.  
  37. $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
  38. $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
  39.  
  40. $output .= $indent . '<li' . $id . $value . $class_names .'>';
  41.  
  42. // add span with number here
  43. if ( $depth == 0 ) { // remove if statement if depth check is not required
  44. $output .= sprintf( '<span>%02s.</span>', $this->number++ );
  45. }
  46.  
  47. $atts = array();
  48. $atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
  49. $atts['target'] = ! empty( $item->target ) ? $item->target : '';
  50. $atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
  51. $atts['href'] = ! empty( $item->url ) ? $item->url : '';
  52.  
  53. $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );
  54.  
  55. $attributes = '';
  56. foreach ( $atts as $attr => $value ) {
  57. if ( ! empty( $value ) ) {
  58. $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
  59. $attributes .= ' ' . $attr . '="' . $value . '"';
  60. }
  61. }
  62.  
  63. $item_output = $args->before;
  64. $item_output .= '<a'. $attributes .'>';
  65. $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
  66. $item_output .= '</a>';
  67. $item_output .= $args->after;
  68.  
  69. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  70. }
  71.  
  72. }
  73.  
  74. wp_nav_menu(
  75. array(
  76. "container" => "nav",
  77. "container_class" => "container",
  78. "container_id" => "nav",
  79. "fallback_cb" => false,
  80. "menu_class" => "six columns omega main-nav sf-menu",
  81. "theme_location" => "main-nav",
  82. "walker" => 'Wpse8170_Menu_Walker',
  83. )
  84. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement