I have a custom class Walker_Page that I have expanded as follows:
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"; } }
But I do not get any results from the start_lvl or end_lvl . Is there something that I have lost here or that I need to return? Im getting the output <li> from start_el() .
Update Using
This is how I use the 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);
source share