Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 504799

Problem using output buffer within walker

$
0
0

Replies: 1

I’m trying to use the output buffer to get the content for dynamic_sidebar() from within a menu walker. The result I just doesn’t place the content within the expected <div>, but instead places it outside the

  • for the menu item. I just can’t make sense of it. If I perform the same buffering outside the start_el function, then I get the expected result, though of course not where I need it. Is there something going on here that I’m not aware of?

    class Menu_With_Description extends Walker_Nav_Menu {
    function start_el( &$output, $item, $depth = 0, $args = array(), $current_object_id = 0) {
    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 = ‘ class=”‘ . esc_attr( $class_names ) . ‘ menu-level-‘ . $depth . ‘”‘;

    $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 .’>’;
    $item_output .= $args->link_before . apply_filters( ‘the_title’, $item->title, $item->ID ) . $args->link_after;
    $item_output .= ‘‘;
    //$item_output .= ‘<span class=”menu-description”>’ . $item->description . ‘</span>’;

    if ( is_active_sidebar( ‘mega-menu-widget-area-‘ . $item->ID ) ) {
    $item_output .= “<div id=\”mega-menu-{$item->ID}\” class=\”mega-menu\”>”;
    ob_start();
    $item_output .= dynamic_sidebar( ‘mega-menu-widget-area-‘ . $item->ID );;
    ob_end_flush();
    $item_output .= “</div>”;
    }

    $item_output .= $args->after;

    $output .= apply_filters( ‘walker_nav_menu_start_el’, $item_output, $item, $depth, $args );
    }
    }


  • Viewing all articles
    Browse latest Browse all 504799

    Trending Articles



    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>