Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Wyjątek od powielania str_repeat
Forum PHP.pl > Forum > Przedszkole
4lex
Hejka!

Mam taki problem. Chciałbym po ostatnim znaczniku </li> dodać swój tekst tak, żeby nie był powielony, ale str_repeat mi go powiela.


  1. public function end_el( &$output, $item, $depth = 0, $args = array() ) {
  2. $indent .= str_repeat("\t", $depth);
  3.  
  4. if ($this->ewf_mm_active && $depth == 1){
  5. $output .= "</div>\n";
  6. }else{
  7. $output .= $indent . "\n</li>\n";
  8. }
  9. }


Wiecie może jak to rozwiązać? W razie potrzeby mogę wrzucić resztę pliku (jest to plik obsługujący menu w WordPressie).

Z góry dziękuję za pomoc.
LowiczakPL
musi być cała metoda bo bez tego ciężko się domyśleć
4lex
  1. // Register menus region
  2. //
  3. if ( function_exists( 'register_nav_menus' ) ) {
  4. register_nav_menus(
  5. 'top-menu' => __('Top Menu',EWF_SETUP_THEME_DOMAIN),
  6. )
  7. );
  8. }
  9.  
  10.  
  11.  
  12. // Attach menu action
  13. //
  14. add_action('ewf-menu-top', 'ewf_action_menuTopInstall');
  15.  
  16. // To use it anyware on template add
  17. // do_action('ewf-menu-top');
  18.  
  19.  
  20.  
  21.  
  22. // Attach menu on region
  23. //
  24. function ewf_action_menuTopInstall(){
  25. $ewf_menu_registred = has_nav_menu('top-menu');
  26. $ewf_menu_walker = new EWF_Walker_Nav_Frontend;
  27.  
  28. if($ewf_menu_registred){
  29. wp_nav_menu( array(
  30. 'theme_location' => 'top-menu',
  31. 'container_class' => null,
  32. 'container' => null,
  33. 'menu_id' => 'menu',
  34. 'class' => null,
  35. 'walker' => $ewf_menu_walker,
  36. 'menu_class' => 'sf-menu fixed' ));
  37. }else{
  38. echo '<p class="error-no-menu">'.__('Menu not selected - Please review documentation!',EWF_SETUP_THEME_DOMAIN).'</p>';
  39. }
  40. }
  41.  
  42.  
  43.  
  44. // Custom Walker to load menus with icons on Front End
  45. //
  46. class EWF_Walker_Nav_Frontend extends Walker_Nav_Menu {
  47.  
  48. var $ewf_mm_active = 0;
  49. var $ewf_mm_columns = 0;
  50.  
  51. public function start_lvl( &$output, $depth = 0, $args = array() ) {
  52. $indent = str_repeat("\t", $depth);
  53. $debug = ' data-mega="'.$this->ewf_mm_active.'" data-depth="'.$depth.'" ';
  54. $debug = null;
  55.  
  56. if($this->ewf_mm_active && $depth === 0 ){
  57. $output .= "\n$indent<div$debug class='sf-mega {ewf-mm-cols}'>\n"; // DIV
  58. }else{
  59. $output .= "\n$indent<ul$debug class='sub-menu'>\n";
  60. }
  61.  
  62. }
  63.  
  64. public function end_lvl(&$output, $depth = 0, $args = array()) {
  65. $indent = str_repeat("\t", $depth);
  66. $debug = ' data-mega="'.$this->ewf_mm_active.'" data-depth="'.$depth.'" ';
  67. $debug = null;
  68.  
  69. if($this->ewf_mm_active && $depth === 0 ){
  70. $output .= "</div>\n"; // DIV
  71. $output = str_replace ('{ewf-mm-cols}', 'sf-mega-cols-'.$this->ewf_mm_columns, $output);
  72.  
  73. $this->ewf_mm_active = 0;
  74. $this->ewf_mm_columns = 0;
  75. }else{
  76. $output .= $indent . "</ul>\n";
  77.  
  78. }
  79.  
  80. }
  81.  
  82. public function end_el( &$output, $item, $depth = 0, $args = array() ) {
  83. $indent .= str_repeat("\t", $depth);
  84.  
  85. if ($this->ewf_mm_active && $depth == 1){
  86. $output .= "</div>\n";
  87. }else{
  88. $output .= $indent . "\n</li>\n";
  89. }
  90. }
  91.  
  92.  
  93. public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
  94. global $wp_query;
  95. $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
  96.  
  97. $extra_attr = null;
  98. $item_output = null;
  99.  
  100. $current_url = strtolower($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  101. $item_url = str_replace(array('http://', 'https://'),'',strtolower($item->url));
  102.  
  103. $page_fields = get_post( $item->object_id);
  104. $page_slug = $page_fields->post_name;
  105.  
  106.  
  107. $classes = empty( $item->classes ) ? array() : (array) $item->classes;
  108. $classes[] = 'menu-item-' . $item->ID;
  109.  
  110. if ($item->mega_menu){
  111. $this->ewf_mm_active = 1;
  112. $classes['mega-menu'] = 'mega-menu';
  113.  
  114. if ($depth) $classes[] = 'sf-mega-section';
  115. }
  116.  
  117. if ($item_url==$current_url){
  118. $classes[] = 'current';
  119. }
  120.  
  121.  
  122. $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
  123. $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
  124.  
  125.  
  126. if ($this->ewf_mm_active && $depth == 1){
  127. $this->ewf_mm_columns++;
  128. $class_names = ' class="sf-mega-section" ';
  129. $output .= $indent . '<div '.$extra_attr.$class_names.'>'."\n";
  130. }else{
  131.  
  132. if (!$this->ewf_mm_active){
  133. $class_names = str_replace('menu-item-has-children', 'menu-item-has-children dropdown', $class_names);
  134. }
  135.  
  136. $output .= $indent . '<li '.$extra_attr.$class_names.'>'."\n";
  137.  
  138. $attributes = ! empty( $item->title ) ? ' title="' . esc_attr( $item->title ) .'"' : '';
  139. $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
  140. $attributes .= ! empty( $item->url ) ? ' href="' . $item->url .'"' : '';
  141.  
  142. $item_output = $args->before;
  143. $item_output .= $indent . '<a'. $attributes .' rel="page-'.$item->object_id.'" ><span>';
  144. $item_output .= $args->link_before;
  145. if ($item->icon){
  146. $item_output .= '<i class="'.$item->icon.'"></i> ';
  147. }
  148. $item_output .= apply_filters( 'the_title', $item->title, $item->ID );
  149. $item_output .= $args->link_after;
  150. $item_output .= '</span></a>';
  151. $item_output .= $args->after;
  152.  
  153. }
  154.  
  155. $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
  156. }
  157.  
  158. }
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.