WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Menu Widget
[resolved] Update: Title Dependency (1 post)

  1. Joe Donahue, Senior Web Developer
    Member
    Posted 2 years ago #

    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'];
    }
    }

    http://wordpress.org/extend/plugins/advanced-menu-widget/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 2 years ago by Joe Donahue, Senior Web Developer
  • This topic is resolved
  • WordPress version: 3.3.1