/inc/lib-foundation.php

  1. <?php 
  2. /** 
  3. * Functions for Bootstrap Framework 
  4. * 
  5. * @package advantage 
  6. * @since 1.0 
  7. */ 
  8. class advantage_bootstrap_walker extends Walker_Nav_Menu { 
  9. function start_lvl( &$output, $depth ) { 
  10. $indent = str_repeat( "\t", $depth ); 
  11. $output .= "\n$indent<ul class=\"dropdown-menu\">\n";  
  12.  
  13. function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { 
  14. global $wp_query; 
  15. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; 
  16.  
  17. if (strcasecmp($item->title, 'divider')) { 
  18. $class_names = $value = ''; 
  19. $classes = empty( $item->classes ) ? array() : (array) $item->classes; 
  20. // $classes[] = ($item->current && 0 == $depth) ? 'active' : ''; 
  21. $classes[] = 'menu-item-' . $item->ID; 
  22. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); 
  23.  
  24. if ( $args->has_children && 0 < $depth ) 
  25. $class_names .= ' dropdown-submenu'; 
  26. elseif( $args->has_children && 0 == $depth ) 
  27. $class_names .= ' dropdown'; 
  28.  
  29. $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; 
  30.  
  31. $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); 
  32. $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; 
  33.  
  34. $output .= $indent . '<li' . $id . $value . $class_names .'>'; 
  35.  
  36. $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : ''; 
  37. $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : ''; 
  38. $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : ''; 
  39. $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : ''; 
  40. //$attributes .= ($args->has_children) ? ' data-toggle="dropdown" data-target="#" class="dropdown-toggle"' : ''; 
  41.  
  42. $item_output = $args->before; 
  43. $item_output .= '<a'. $attributes .'>'; 
  44. $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after; 
  45. $item_output .= ($args->has_children && $depth == 0) ? ' <span class="caret"></span></a>' : '</a>'; 
  46. $item_output .= $args->after; 
  47.  
  48. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); 
  49. } else { 
  50. $output .= $indent . '<li class="divider">'; 
  51.  
  52. function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) { 
  53.  
  54. if ( !$element ) 
  55. return; 
  56.  
  57. $id_field = $this->db_fields['id']; 
  58.  
  59. //display this element 
  60. if ( is_array( $args[0] ) ) 
  61. $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] ); 
  62. elseif ( is_object( $args[0] ) ) 
  63. $args[0]->has_children = ! empty( $children_elements[$element->$id_field] ); 
  64. $cb_args = array_merge( array(&$output, $element, $depth), $args); 
  65. call_user_func_array(array(&$this, 'start_el'), $cb_args); 
  66. $id = $element->$id_field; 
  67.  
  68. // descend only when the depth is right and there are childrens for this element 
  69. if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) { 
  70.  
  71. foreach( $children_elements[ $id ] as $child ) { 
  72. if ( !isset($newlevel) ) { 
  73. $newlevel = true; 
  74. //start the child delimiter 
  75. $cb_args = array_merge( array(&$output, $depth),  
  76. $args); 
  77. call_user_func_array( array(&$this, 'start_lvl'), $cb_args); 
  78. $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output ); 
  79. unset( $children_elements[ $id ] ); 
  80.  
  81. if ( isset($newlevel) && $newlevel ) { 
  82. //end the child delimiter 
  83. $cb_args = array_merge( array(&$output, $depth), $args); 
  84. call_user_func_array(array(&$this, 'end_lvl'), $cb_args); 
  85.  
  86. //end this element 
  87. $cb_args = array_merge( array(&$output, $element, $depth), $args); 
  88. call_user_func_array(array(&$this, 'end_el'), $cb_args); 
  89.  
  90. function advantage_nav_fb() { 
  91. echo '<ul class="nav">'; 
  92. wp_list_pages( array( 
  93. 'echo' => 1,  
  94. 'title_li' => '',  
  95. 'sort_column' => 'menu_order, post_title',  
  96. 'walker' => new advantage_page_walker(),  
  97. 'post_type' => 'page',  
  98. 'post_status' => 'publish' 
  99. ) ); 
  100. echo '</ul>'; 
  101.  
  102. class advantage_page_walker extends Walker_Page { 
  103.  
  104. function start_el( &$output, $page, $depth, $args, $current_page ) { 
  105. $item_html = ''; 
  106. parent::start_el( $item_html, $page, $depth, $args, $current_page ); 
  107. $css_class = array( 'page_item', 'page-item-'.$page->ID ); 
  108. if ( $args['has_children'] && 0 == $depth ) { 
  109. $css_class[] = 'dropdown'; 
  110. } elseif ( $args['has_children'] && 0 < $depth ) 
  111. $css_class[] = 'dropdown-submenu'; 
  112.  
  113. $css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) ); 
  114. if ( $args['has_children'] && 0 == $depth ) { 
  115. $item_html = '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . apply_filters( 'the_title', $page->post_title, $page->ID ) . '<span class="caret dropdown-toggle" data-toggle="dropdown"></span></a>';  
  116. else 
  117. $item_html = '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . apply_filters( 'the_title', $page->post_title, $page->ID ) . '</a>'; 
  118. $output .= $item_html; 
  119.  
  120. function start_lvl( &$output, $depth = 0, $args = array() ) { 
  121. $output .= "\n<ul class=\"dropdown-menu\">\n"; 
  122.  
  123. if ( ! function_exists( 'advantage_content_class' ) ) : 
  124. function advantage_content_class() { 
  125. global $advantage_options; 
  126. $class = "span" . $advantage_options['content'] . ' ' ; 
  127. if ( 2 == $advantage_options['sidebarpos'] && ( $advantage_options['sidebar1'] > 0 || $advantage_options['sidebar2'] > 0 ) ) { 
  128. if ( ( $advantage_options['content'] + $advantage_options['sidebar1'] + $advantage_options['sidebar2'] ) > 12 ) { 
  129. if ($advantage_options['sidebar1'] > $advantage_options['sidebar2']) 
  130. $push_col = $advantage_options['sidebar1'];  
  131. else 
  132. $push_col = $advantage_options['sidebar2']; 
  133. else { 
  134. $push_col = $advantage_options['sidebar1'] + $advantage_options['sidebar2'];  
  135. $class = $class . "push" . $push_col . ' '; 
  136. elseif ( 3 == $advantage_options['sidebarpos'] && $advantage_options['sidebar1'] > 0 ) { 
  137. $push_col = $advantage_options['sidebar1'];  
  138. $class = $class . "push" . $push_col . ' ';  
  139. return $class; 
  140. endif; 
  141.  
  142. if ( ! function_exists( 'advantage_grid_columns' ) ) : 
  143. function advantage_grid_columns( $col ) { 
  144. return 'span' . $col; 
  145. endif;  
  146.  
  147. if ( ! function_exists( 'advantage_grid_full' ) ) : 
  148. function advantage_grid_full() { 
  149. return "span12"; 
  150. endif; 
.