category_megamenu == true ) {
return;
}
if ( $this->megamenu && $depth == 0 ) {
$output .= "\n$indent
mega_class\">\n";
$output .= "\n<$this->mega_tag class=\"container\">\n";
} elseif ( $this->megamenu && $depth == 1 ) {
$output .= "\n$indent
\n";
} else {
$output .= "\n$indent
\n";
} elseif ( $this->megamenu && $depth == 1 ) {
$output .= "\n$indent\n";
} else {
$output .= "\n$indent\n";
}
}
/**
* Modified the menu output.
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param array $args An array of arguments. @see wp_nav_menu()
* @param int $id Current item ID.
*/
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
if ( $this->category_megamenu && $depth > 0 )
return;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
// Set up empty variable.
$class_names = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
if ( in_array( 'menu-item-home', $item->classes ) ) {
$classes[] = 'home_item';
}
if ( $item->megamenu ) {
$classes[] = 'sf-mega-parent';
}
/**
* Filter the CSS class(es) applied to a menu item's .
*
* @param array $classes The CSS classes that are applied to the menu item's .
* @param object $item The current menu item.
* @param array $args An array of wp_nav_menu() arguments.
*/
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
/**
* Filter the ID applied to a menu item's .
*
* @param string $menu_id The ID that is applied to the menu item's .
* @param object $item The current menu item.
* @param array $args An array of wp_nav_menu() arguments.
*/
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
// output.
$output .= $indent . '';
// link attributes
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
// Check the current menu location.
$icon = '';
if ( in_array( 'menu-item-home', $item->classes ) ) {
$icon = ' ';
}
if ( $this->megamenu && $depth == 1 && ! $this->category_megamenu ) {
$item_output = sprintf( '%1$s%2$s%3$s',
$args->before,
apply_filters( 'the_title', $item->title, $item->ID ),
$args->after
);
} elseif ( $item->megamenu && $item->object == 'category' && $depth == 0 ) {
$item_output = sprintf( '%1$s%3$s%4$s%5$s%6$s%7$s',
$args->before,
$attributes,
$args->link_before,
$icon,
apply_filters( 'the_title', $item->title, $item->ID ),
$args->link_after,
$args->after
);
$item_output .= "\n$indent\n";
$item_output .= beginner_get_latest_posts( array( 'item' => $item ) );
$item_output .= '
';
} else {
// Menu output.
$item_output = sprintf( '%1$s%3$s%4$s%5$s%6$s%7$s',
$args->before,
$attributes,
$args->link_before,
$icon,
apply_filters( 'the_title', $item->title, $item->ID ),
$args->link_after,
$args->after
);
}
// $item_output .= $this->category_megamenu;
// Build html
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
/**
* Initialize the mega menu.
*/
if ( $depth == 0 ) {
$this->megamenu = false;
$this->category_megamenu = false;
$this->current_item = null;
}
if ( $item->megamenu ) {
$this->megamenu = true;
$this->current_item = $item;
}
if ( $item->megamenu && $item->object == 'category' ) {
$this->category_megamenu = true;
}
}
/**
* Ends the element output, if needed.
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Page data object. Not used.
* @param int $depth Depth of page. Not Used.
* @param array $args An array of arguments. @see wp_nav_menu()
*/
function end_el( &$output, $item, $depth = 0, $args = array() ) {
if ( $this->category_megamenu && $depth > 0 ) {
return;
} elseif( $this->megamenu && $depth == 1 && ! $this->category_megamenu ) {
$output .= "\n";
} else {
$output .= "\n";
}
}
}
/**
* Custom latest posts based on parent category on top-level menu.
*
* @since 1.0.0
*/
function beginner_get_latest_posts( $args ) {
extract( $args );
$output = '';
$output .= '';
$args = array(
'cat' => $item->object_id,
'posts_per_page' => 4,
'ignore_sticky_posts' => 1
);
$default = apply_filters( 'beginner_megamenu_posts_args', $args );
$posts = new WP_Query( $default );
if ( $posts->have_posts() ) :
while ( $posts->have_posts() ) : $posts->the_post();
$output .= '- ';
$output .= '';
if ( has_post_thumbnail() ) {
$output .= get_the_post_thumbnail( get_the_ID(), 'beginner-megamenu-posts', array( 'class' => 'entry-thumbnail', 'alt' => esc_attr( get_the_title() ) ) );
} else {
$output .= '
';
}
if ( has_post_format( 'video' ) ) {
$output .= '';
$output .= '';
$output .= '';
}
$output .= '' . esc_attr( get_the_title() ) . '
';
$output .= '';
$output .= ' ';
endwhile;
endif;
wp_reset_postdata();
$output .= '
';
return $output;
}
// add_filter( 'beginner_mega_menu_end_lvl', 'beginner_get_latest_posts' );