';
} else {
$output .= $indent . '
';
}
} else {
$output .= $indent . '
';
}
$atts = array();
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
if ( '_blank' === $item->target && empty( $item->xfn ) ) {
$atts['rel'] = 'noopener noreferrer';
} else {
$atts['rel'] = $item->xfn;
}
$atts['href'] = $item->url;
$atts['aria-current'] = $item->current ? 'page' : '';
$atts = apply_filters( 'treviso_nav_menu_link_attributes', $atts, $item, $args, $depth );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( is_scalar( $value ) && '' !== $value && false !== $value ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
$title = apply_filters( 'treviso_the_title', $item->title, $item->ID );
$title = apply_filters( 'treviso_nav_menu_item_title', $title, $item, $args, $depth );
$item_classes = array();
// Enable a navbar button.
if ( in_array( 'is-button', $classes, true ) ) {
$item_classes = array( 'button is-fullwidth navbar-button' );
// Use a small button for mega menu footer.
if ( in_array( 'is-footer-left', $classes, true ) || in_array( 'is-footer-right', $classes, true ) ) {
$item_classes = array( 'button is-small' );
}
} else {
$item_classes = array( 'navbar-link' );
// Remove arrow when navbar-link has no children.
if ( ! $args->walker->has_children ) {
$item_classes[] = 'is-arrowless';
}
}
if ( 0 === $depth ) {
$item_classes[] = 'top';
}
$item_class_names = array_map( 'esc_attr', $item_classes );
$item_class_names = $item_class_names ? ' class="' . implode( ' ', $item_class_names ) . '"' : '';
$item_output = $args->before;
// Display font-awesome elements and wrap in span.
if ( $fa_classes ) {
$fa_class_names = array_map( 'esc_attr', $fa_classes );
$fa_class_names = ' class="' . implode( ' ', $fa_class_names ) . '"';
$item_output .= ( isset( $atts['href'] ) ? '
';
$item_output .= '';
$item_output .= $args->link_before . $title . $args->link_after;
$item_output .= ' ' . ( isset( $atts['href'] ) ? ' ' : '
' );
} else {
$item_output .= '
';
$item_output .= $args->link_before . $title . $args->link_after;
$item_output .= ' ';
}
$item_output .= $args->after;
// Reset is-img, is-post and is-footer items html.
if ( $this->mega_menu && ( in_array( 'is-footer', $classes, true ) || in_array( 'is-img', $classes, true ) || in_array( 'is-post', $classes, true ) ) ) {
$item_output = '';
}
if ( in_array( 'is-search', $classes, true ) ) {
$item_output = "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= get_search_form( false );
$item_output .= "{$n}{$indent}
{$n}";
}
// Override $item_output for mega menu specific objects.
if ( $this->mega_menu ) {
if ( in_array( 'is-img', $classes, true ) ) {
$item_output = "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent} {$n}";
$item_output .= "{$n}{$indent} {$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
" . $title . "
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
} elseif ( in_array( 'is-post', $classes, true ) ) {
$matches = preg_grep( '/post-.*/m', $classes );
$post_id = reset( $matches );
$post_title = '';
$post_img = '';
$post_url = '';
if ( $post_id ) {
$post_id = str_replace( 'post-', '', $post_id );
$post_title = get_the_title( $post_id );
$post_img = get_the_post_thumbnail( $post_id );
$post_url = get_the_permalink( $post_id );
} else {
$latest_post_query = new WP_Query( 'posts_per_page=1' );
if ( have_posts() ) :
while ( $latest_post_query->have_posts() ) :
$latest_post_query->the_post();
$post_title = get_the_title();
$post_img = get_the_post_thumbnail();
$post_url = get_the_permalink();
endwhile;
endif;
}
$item_output = "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}{$n}";
$item_output .= "{$n}{$indent}" . $post_img . "{$n}";
$item_output .= "{$n}{$indent} {$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
" . $post_title . " {$n}";
$item_output .= "{$n}{$indent}
' . esc_html__( 'Read more', 'treviso' ) . "... {$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
$item_output .= "{$n}{$indent}
{$n}";
} elseif ( in_array( 'is-footer', $classes, true ) ) {
$item_output = '';
} elseif ( in_array( 'is-footer-left', $classes, true ) || in_array( 'is-footer-right', $classes, true ) ) {
if ( ! in_array( 'is-button', $classes, true ) ) {
$item_output = '
' . $title . ' ';
}
} elseif ( 1 === $depth ) {
if ( in_array( 'no-header', $classes, true ) ) {
$item_output = '
';
} else {
$item_output = '
' . $title . ' ';
}
}
}
$output .= apply_filters( 'treviso_nav_menu_start_el', $item_output, $item, $depth, $args );
}
/**
* Ends the element output, if needed.
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $item Page data object. Not used.
* @param int $depth Depth of page. Not Used.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function end_el( &$output, $item, $depth = 0, $args = null ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
// Footer alignment classes require an extra closing div.
if ( $depth >= 0 && $this->mega_menu && ( in_array( 'is-footer-left', $classes, true ) || in_array( 'is-footer-right', $classes, true ) ) ) {
$output .= "