Site icon Hip-Hop Website Design and Development

has_children in customized nav_walker

I’m attempting to create customized menu nav walker. I added beneath code

perform display_element( $aspect, &$children_elements, $max_depth, $depth=0, $args, &$output )
{
    $id_field = $this->db_fields['id'];
    if ( is_object( $args[0] ) ) {
        $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
    }
    return mum or dad::display_element( $aspect, $children_elements, $max_depth, $depth, $args, $output );
}

Because of this I can use if ( $args->has_children ) assertion in my start_el perform, sadly the identical code does not appear to be working in end_el perform.

Total code:

class CSS_Menu_Walker2 extends Walker {
  /**
   * What the category handles.
   *
   * @see Walker::$tree_type
   * @since 3.0.0
   * @var string
   */
  public $tree_type = array( 'post_type', 'taxonomy', 'customized' );

  /**
   * Database fields to make use of.
   *
   * @see Walker::$db_fields
   * @since 3.0.0
   * @todo Decouple this.
   * @var array
   */
  public $db_fields = array( 'mum or dad' => 'menu_item_parent', 'id' => 'db_id' );

  /**
   * Begins the record earlier than the weather are added.
   *
   * @see Walker::start_lvl()
   *
   * @since 3.0.0
   *
   * @param string $output Handed by reference. Used to append further content material.
   * @param int    $depth  Depth of menu merchandise. Used for padding.
   * @param array  $args   An array of arguments. @see wp_nav_menu()
   */
  public perform start_lvl( &$output, $depth = 0, $args = array() ) {
    $indent = str_repeat("t", $depth);
    $output .= "n$indent <div class="collapsible-body"> <ul class="sub-menu">n";
  }

  /**
   * Ends the record of after the weather are added.
   *
   * @see Walker::end_lvl()
   *
   * @since 3.0.0
   *
   * @param string $output Handed by reference. Used to append further content material.
   * @param int    $depth  Depth of menu merchandise. Used for padding.
   * @param array  $args   An array of arguments. @see wp_nav_menu()
   */
  public perform end_lvl( &$output, $depth = 0, $args = array() ) {
    $indent = str_repeat("t", $depth);

    $output .= "$indent</ul></div>n";
  }

  /**
   * Begin the aspect output.
   *
   * @see Walker::start_el()
   *
   * @since 3.0.0
   *
   * @param string $output Handed by reference. Used to append further content material.
   * @param object $merchandise   Menu merchandise information object.
   * @param int    $depth  Depth of menu merchandise. Used for padding.
   * @param array  $args   An array of arguments. @see wp_nav_menu()
   * @param int    $id     Present merchandise ID.
   */


    perform display_element( $aspect, &$children_elements, $max_depth, $depth=0, $args, &$output )
    {
        $id_field = $this->db_fields['id'];
        if ( is_object( $args[0] ) ) {
            $args[0]->has_children = ! empty( $children_elements[$element->$id_field] );
        }
        return mum or dad::display_element( $aspect, $children_elements, $max_depth, $depth, $args, $output );
    }



  public perform start_el( &$output, $merchandise, $depth = 0, $args = array(), $id = 0 ) {


    $indent = ( $depth ) ? str_repeat( "t", $depth ) : '';

    $lessons = empty( $item->lessons ) ? array() : (array) $item->lessons;
    $lessons[] = 'menu-item-' . $item->ID;

    /**
     * Filter the CSS class(es) utilized to a menu merchandise's record merchandise aspect.
     *
     * @since 3.0.0
     * @since 4.1.0 The `$depth` parameter was added.
     *
     * @param array  $lessons The CSS lessons which can be utilized to the menu merchandise's `<li>` aspect.
     * @param object $merchandise    The present menu merchandise.
     * @param array  $args    An array of {@see wp_nav_menu()} arguments.
     * @param int    $depth   Depth of menu merchandise. Used for padding.
     */
    $class_names = be a part of( ' ', apply_filters( 'nav_menu_css_class', array_filter( $lessons ), $merchandise, $args, $depth ) );
    $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';

    /**
     * Filter the ID utilized to a menu merchandise's record merchandise aspect.
     *
     * @since 3.0.1
     * @since 4.1.0 The `$depth` parameter was added.
     *
     * @param string $menu_id The ID that's utilized to the menu merchandise's `<li>` aspect.
     * @param object $merchandise    The present menu merchandise.
     * @param array  $args    An array of {@see wp_nav_menu()} arguments.
     * @param int    $depth   Depth of menu merchandise. Used for padding.
     */
    $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $merchandise, $args, $depth );
    $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';

    if ( $args->has_children ) {
    $output .= $indent .  '<ul class="collapsible collapsible-accordion">';
    $output .= $indent . '<a category="collapsible-header  waves-effect waves-teal ">';
    }
    $output .= $indent . '<li' . $id . $class_names .'>';

    $atts = array();
    $atts['title']  = ! empty( $item->attr_title ) ? $item->attr_title : '';
    $atts['target'] = ! empty( $item->goal )     ? $item->goal     : '';
    $atts['rel']    = ! empty( $item->xfn )        ? $item->xfn        : '';
    $atts['href']   = ! empty( $item->url )        ? $item->url        : '';

    /**
     * Filter the HTML attributes utilized to a menu merchandise's anchor aspect.
     *
     * @since 3.6.0
     * @since 4.1.0 The `$depth` parameter was added.
     *
     * @param array $atts {
     *     The HTML attributes utilized to the menu merchandise's `<a>` aspect, empty strings are ignored.
     *
     *     @sort string $title  Title attribute.
     *     @sort string $goal Goal attribute.
     *     @sort string $rel    The rel attribute.
     *     @sort string $href   The href attribute.
     * }
     * @param object $merchandise  The present menu merchandise.
     * @param array  $args  An array of {@see wp_nav_menu()} arguments.
     * @param int    $depth Depth of menu merchandise. Used for padding.
     */
    $atts = apply_filters( 'nav_menu_link_attributes', $atts, $merchandise, $args, $depth );

    $attributes = '';
    foreach ( $atts as $attr => $worth ) {
      if ( ! empty( $worth ) ) {
        $worth = ( 'href' === $attr ) ? esc_url( $worth ) : esc_attr( $worth );
        $attributes .= ' ' . $attr . '="' . $worth . '"';
      }
    }

    $item_output = $args->earlier than;
    if (!$args->has_children ) 
    $item_output .= '<a'. $attributes .'>';
    /** This filter is documented in wp-includes/post-template.php */
    $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    if (!$args->has_children ) 
    $item_output .= '</a>';
    $item_output .= $args->after;



    /**
     * Filter a menu merchandise's beginning output.
     *
     * The menu merchandise's beginning output solely contains `$args->earlier than`, the opening `<a>`,
     * the menu merchandise's title, the closing `</a>`, and `$args->after`. Presently, there's
     * no filter for modifying the opening and shutting `<li>` for a menu merchandise.
     *
     * @since 3.0.0
     *
     * @param string $item_output The menu merchandise's beginning HTML output.
     * @param object $merchandise        Menu merchandise information object.
     * @param int    $depth       Depth of menu merchandise. Used for padding.
     * @param array  $args        An array of {@see wp_nav_menu()} arguments.
     */
    $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $merchandise, $depth, $args );

  }

  /**
   * Ends the aspect output, if wanted.
   *
   * @see Walker::end_el()
   *
   * @since 3.0.0
   *
   * @param string $output Handed by reference. Used to append further content material.
   * @param object $merchandise   Web page information object. Not used.
   * @param int    $depth  Depth of web page. Not Used.
   * @param array  $args   An array of arguments. @see wp_nav_menu()
   */
  public perform end_el( &$output, $merchandise, $depth = 0, $args = array() ) {

    $output .= "</li>n";

  }

} // Walker_Nav_Menu
?>
a

Am I doing one thing flawed?