2015-12-28 4 views
5

Mam klasę niestandardową Walker_Page że mam rozszerzony tak:rozszerzony Walker_Page nie emituje zwyczaj start_lvl() lub() end_lvl

class List_Nav extends Walker_Page { 
    function start_lvl(&$output, $depth = 0, $args = array()) { 
    $indent = str_repeat("\t", $depth); 
    $output .= "\n$indent<ul class='ListNav'>\n"; 
    } 

    function start_el(&$output, $page, $depth = 0, $args = array(), $current_page = 0) { 
    $output .= '<li class="ListNav-item">'; 
    $output .= '<a class="ListNav-link" href="' . get_permalink($page->ID) . '">' . apply_filters('the_title', $page->post_title, $page->ID) . '</a>'; 
    $output .= '</li>'; 
    } 

    function end_lvl(&$output, $depth = 0, $args = array()) { 
    $indent = str_repeat("\t", $depth); 
    $output .= "\n$indent</ul>\n"; 
    } 
} 

Ale ja nie dostaję żadnego wyjścia z start_lvl lub end_lvl Funkcje. Czy jest tu coś, czego tu brakuje, czy też muszę wrócić? Otrzymuję dane wyjściowe <li> z start_el().


Aktualizacja z wykorzystaniem

Oto jak używam Walker:

if ($post->post_parent) { 
    $ancestors=get_post_ancestors($post->ID); 
    $root = count($ancestors) - 1; 
    $top_parent = $ancestors[$root]; 
} else { 
    $top_parent = $post->ID; 
} 

$page_list_args = array(
    'child_of'  => $top_parent, 
    'depth'  => 0, 
    'title_li'  => false, 
    'walker'  => new List_Nav 
); 

wp_list_pages($page_list_args); 
+0

Nie zwracasz zmiennej wyjściowej! prawda? – Thamilan

+0

Powiedz nam, jak używasz tej klasy, abyśmy mogli odtworzyć twoją sprawę? – aeryaguzov

+0

@Thamizhan Nic .. I nie otrzymuję niczego próbującego 'var_dump',' echo', 'return' lub nawet' die() '. –

Odpowiedz

2

Wygląda start_lvl() i end_lvl() jest zawsze nazywane wewnątrz pętli i nigdy na pierwszym poziomie. Dotyczy to wszystkich WordPress Walkers, takich jak Walker_Nav_Menu, Walker_Page i Walker_Category.

To nie jest bardzo jasne, ale można go odgadnąć, jeśli spojrzeć na Core Walker code lub gdy czytasz Walker documentation o start_lvl().

Ale w dokumentacji Walker::start_lvl to po prostu mówi, że ...

Rozpoczyna listę zanim elementy są dodawane.

Więc być może, co należy zrobić, to aktualizacja w dokumentach.