'Use this widget to add one of your custom menus as a widget.' );
parent::__construct( 'advanced_menu', 'Advanced Menu', $widget_ops );
}
function widget($args, $instance) {
$items_wrap = !empty( $instance['dropdown'] ) ? 'Select %3$s ' : '
';
$only_related_walker = ( $instance['only_related'] == 2 || $instance['only_related'] == 3 || 1 == 1 )? new AMW_Related_Sub_Items_Walker : new Walker_Nav_Menu;
$strict_sub = $instance['only_related'] == 3 ? 1 : 0;
$only_related = $instance['only_related'] == 2 || $instance['only_related'] == 3 ? 1 : 0;
$depth = $instance['depth'] ? $instance['depth'] : 0;
$container = isset( $instance['container'] ) ? $instance['container'] : 'div';
$container_id = isset( $instance['container_id'] ) ? $instance['container_id'] : '';
$menu_class = isset( $instance['menu_class'] ) ? $instance['menu_class'] : 'menu';
$before = isset( $instance['before'] ) ? $instance['before'] : '';
$after = isset( $instance['after'] ) ? $instance['after'] : '';
$link_before = isset( $instance['link_before'] ) ? $instance['link_before'] : '';
$link_after = isset( $instance['link_after'] ) ? $instance['link_after'] : '';
$filter = ! empty( $instance['filter'] ) ? $instance['filter'] : 0;
$filter_selection = $instance['filter_selection'] ? $instance['filter_selection'] : 0;
$custom_widget_class = isset( $instance['custom_widget_class'] ) ? trim($instance['custom_widget_class']) : '';
$include_parent = ! empty( $instance['include_parent'] ) ? 1 : 0;
$post_parent = ! empty( $instance['post_parent'] ) ? 1 : 0;
$description = ! empty( $instance['description'] ) ? 1 : 0;
$start_depth = ! empty($instance['start_depth']) ? absint($instance['start_depth']) : 0;
$hide_title = ! empty( $instance['hide_title'] ) ? 1 : 0;
$parent_title = ! empty( $instance['parent_title'] ) ? 1 : 0;
$container_class ='';
// Get menu
$menu = wp_get_nav_menu_object( $instance['nav_menu'] );
if ( ! $menu || is_wp_error($menu) )
return;
$menu_args = array(
'echo' => false,
'items_wrap' => '%3$s',
'fallback_cb' => '',
'menu' => $menu,
'walker' => $only_related_walker,
'depth' => $depth,
'only_related' => $only_related,
'strict_sub' => $strict_sub,
'filter_selection' => $filter_selection,
'container' => false,
'container_id' => $container_id,
'menu_class' => $menu_class,
'before' => $before, 'after' => $after,
'link_before' => $link_before,
'link_after' => $link_after,
'filter' => $filter,
'include_parent' => $include_parent,
'post_parent' => $post_parent,
'description' => $description,
'start_depth' => $start_depth,
'dropdown' => $instance['dropdown'],
'parent_title' => $parent_title,
);
$wp_nav_menu = wp_nav_menu( $menu_args );
if ( !$wp_nav_menu && $hide_title )
return;
if ( $custom_widget_class ) {
echo str_replace ('class="', 'class="' . "$custom_widget_class ", $args['before_widget']);
} else {
echo $args['before_widget'];
}
if ( $parent_title && $cached_parent_title = wp_cache_get( 'parent_title_' . $menu->slug ) ) {
$instance['title'] = $cached_parent_title;
}
$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
if ( !empty($instance['title']) )
echo $args['before_title'] . $instance['title'] . $args['after_title'];
if ( $wp_nav_menu ) {
static $menu_id_slugs = array();
$nav_menu ='';
$show_container = false;
if ( $container ) {
$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
if ( in_array( $container, $allowed_tags ) ) {
$show_container = true;
$class = $container_class ? ' class="' . esc_attr( $container_class ) . '"' : ' class="menu-'. $menu->slug .'-container"';
$id = $container_id ? ' id="' . esc_attr( $container_id ) . '"' : '';
$nav_menu .= '<'. $container . $id . $class . '>';
}
}
// Attributes
if ( ! empty( $menu_id ) ) {
$wrap_id = $menu_id;
} else {
$wrap_id = 'menu-' . $menu->slug;
while ( in_array( $wrap_id, $menu_id_slugs ) ) {
if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) )
$wrap_id = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $wrap_id );
else
$wrap_id = $wrap_id . '-1';
}
}
$menu_id_slugs[] = $wrap_id;
$wrap_class = $menu_class ? $menu_class : '';
$nav_menu .= sprintf( $items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $wp_nav_menu );
if ( $show_container )
$nav_menu .= '' . $container . '>';
echo $nav_menu;
if ( $instance['dropdown'] ) : ?>
false ) );
// If no menus exists, direct the user to go and create some.
if ( !$menus ) {
echo ''. sprintf( __('No menus have been created yet. Create some .'), admin_url('nav-menus.php') ) .'
';
return;
}
?>
/>
/>
/>
>
>
>
>
>
>
>
>
>
>
>
term_id;
$menu_items = wp_get_nav_menu_items($menu_id);
foreach ( $menu_items as $menu_item ) {
echo 'ID ).'>'.$menu_item->title.' ';
}
?>
Select the filter:
/> None
/> Display direct path
/> Display only children of selected item
/>
/>
/>
of the link.') ); ?>
of the link.') ); ?>