jeudi 29 janvier 2015

Add dynamic sidebar in wp nav menu item


I've added a custom menu walker into my theme: 'walker' => new menu_walker


So i've created a navbar_widget function to insert dynamic sidebar at the end of menu item:



function navbar_widget() {
if (function_exists('dynamic_sidebar')) {
ob_start();
dynamic_sidebar($item->sidebar);
$out = ob_get_clean();
return $out;
}
}
add_filter( 'sidebar_filter', 'navbar_widget', 8 );


and i'm calling it in my menu_walker:



class menu_walker extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth, $args) {
...
$item_output .= ' </a>'.apply_filters('sidebar_filter', 'navbar_widget').'';
...
}
}


Everything is great when I'm using static name of dynamic sidebar like:



dynamic_sidebar('Sidebar1');


But I would like to use $item->sidebar to choose it dynamically in admin panel. When I insert dynamic_sidebar($item->sidebar); istead of apply_filters it displays a dynamic sidebar but above the menu.


EDIT: Maybe there is another way to add dynamic sidebar to menu item?


greetings





Aucun commentaire:

Enregistrer un commentaire