Wordpress functions.php: Rozszerzenie nawigacji

Wordpress functions.php: Rozszerzenie nawigacji

class sw_walker extends Walker_Nav_Menu {
    function start_el(&$output, $item, $depth, $args) {
        global $wp_query;
        $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
        $class_names = $value = '';
        $classes = empty( $item->classes ) ? array() : (array) $item->classes;
        $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
        $class_names = '';
        $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
        $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
        $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
        $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
        $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
        $item_output = $args->before;
        $item_output .= '<a'. $attributes .'>';
        
        if (!$item->description) {} else {
            $item_output .= '<span>' . $item->description . '</span>';
        }
        
        $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;

        if (get_current_page_depth($item->object_id)==3) {
            $thumbnail = '';
            if ( has_post_thumbnail( $item->object_id ) ) {
                $thumbnail = get_the_post_thumbnail( $item->object_id, 'ikona' );
            } else {
                $thumbnail = '<img src="'.get_template_directory_uri().'/img/menu_blank.png" alt="'.$item->title.'">';
            }
            $item_output .= $thumbnail;
        };

        //$item_output .= $item->ID;
        $item_output .= '</a>';
        $item_output .= $args->after;
        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    }
}    

function sw_main_nav() {
    $walker = new sw_walker;
        wp_nav_menu(array(
            'menu' => 'top-menu', //nazwa menu
            'theme_location' => 'top-menu',
            'container'       => 'nav', // kontener
            'container_class' => 'top-menu', // klasa kontenera
            'fallback_cb' => 'sw_main_nav_fallback', //menu fallback
            'walker' => $walker // walker
        ));
}

function sw_main_nav_fallback() {
    //wp_page_menu( 'show_home=Home&menu_class=menu' );
}