[Plugin: Advanced Menu Widget] Update: Title Dependency
-
A bug (or unintended feature) is that AMW displays the title, even if the results are empty. The <i>widget</i> function can be updated with the following code to only display the title if the widget generates non-empty results.
function widget($args, $instance) {$only_related_walker = ( $instance['only_related'] == 2 || $instance['only_related'] == 3 || 1 == 1 )? new 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;
$start_depth = !empty($instance['start_depth']) ? absint($instance['start_depth']) : 0;// Get menu
$nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );if ( !$nav_menu )
return;$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
$menu = wp_nav_menu( array( 'echo' => false, 'fallback_cb' => '', 'menu' => $nav_menu, 'walker' => $only_related_walker, 'depth' => $depth, 'only_related' => $only_related, 'strict_sub' => $strict_sub, 'filter_selection' => $filter_selection, 'container' => $container,'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, 'start_depth' => $start_depth ) );
$menu_items = substr_count($menu,'class="menu-item ');if ($menu_items) {
if ( $custom_widget_class ) {
echo str_replace ('class="', 'class="' . "$custom_widget_class ", $args['before_widget']);
} else {
echo $args['before_widget'];
}
if ( !empty($instance['title']) )
echo $args['before_title'] . $instance['title'] . $args['after_title'];
echo $menu;
echo $args['after_widget'];
}
}https://www.ads-software.com/extend/plugins/advanced-menu-widget/
- The topic ‘[Plugin: Advanced Menu Widget] Update: Title Dependency’ is closed to new replies.