Bar separated navigation by extending Walker_Page

This is what I went with in the end. Although it only will work correctly if you are using a depth of one:

class Bar_List_Walker_Page extends Walker_Page {
    public $count;
    public $running_count;
    function __construct() {
        $this->count = 0;
        $this->running_count = 0;
    }
    function start_el(&$output, $page, $depth, $args, $current_page) {
        global $post;
        extract($args, EXTR_SKIP);
        $css_class = array();

        if("partner" == get_post_type( $post ))
            $current_page = get_ID_by_slug("about-us/our-partners");

        if ( !empty($current_page) ) {
            if ( $page->ID == $current_page )
                $css_class[] = 'selected';
        }

        $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page));
        $output .= '<a class="' . $css_class . '" href="' . get_permalink($page->ID) . '">' . apply_filters( 'the_title', $page->post_title, $page->ID ) . '</a>';
    }
    function end_el(&$output, $item, $depth) {
        $this->running_count++;
        if($this->count > $this->running_count)
            $output .= " | ";
    }
    function walk( $elements, $max_depth, $a, $b ) {
        foreach($elements as $element) {
            if($a['child_of'] == $element->post_parent)
                $this->count++;
        }
        return parent::walk( $elements, $max_depth, $a, $b );
    }
}

Leave a Comment