File: //home/dorsetandsomersetairambulance.org.uk/public_html/wp-content/themes/dw-focus/inc/nav.php
<?php
/**
* DW Focus Navigation Walker
*
* @package DW Focus
* @since DW Focus 1.2.1
*/
class DW_Focus_Nav_Walker extends Walker_Nav_Menu {
function check_current( $classes ) {
return preg_match( '/(current[-_])|active|dropdown/', $classes );
}
function start_lvl( &$output, $depth = 0, $args = array() ) {
$output .= "\n<ul class=\"dropdown-menu\">\n";
}
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$item_html = '';
parent::start_el( $item_html, $item, $depth, $args );
if ( $item->is_dropdown && ( 0 === $depth ) ) {
$item_html = str_replace( '<a', '<a class="dropdown-toggle disabled" data-toggle="dropdown" data-target="#"', $item_html );
$item_html = str_replace( '</a>', ' <b class="caret"></b></a>', $item_html );
}
elseif ( stristr( $item_html, 'li class="divider' ) ) {
$item_html = preg_replace( '/<a[^>]*>.*?<\/a>/iU', '', $item_html );
}
elseif ( stristr( $item_html, 'li class="dropdown-header' ) ) {
$item_html = preg_replace( '/<a[^>]*>(.*)<\/a>/iU', '$1', $item_html );
}
$item_html = apply_filters( 'dw_focus_wp_nav_menu_item', $item_html );
$output .= $item_html;
}
function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
$element->is_dropdown = ( ( ! empty( $children_elements[ $element->ID ] ) && ( ( $depth + 1 ) < $max_depth || ( $max_depth === 0 ) ) ) );
if ( $element->is_dropdown ) {
$element->classes[] = 'dropdown';
}
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
}
/**
* Remove the id="" on nav menu items
* Return 'menu-slug' for nav menu classes
*/
function dw_focus_nav_menu_css_class( $classes, $item ) {
$slug = sanitize_title( $item->title );
$classes = preg_replace( '/(current(-menu-|[-_]page[-_])(item|parent|ancestor))/', 'active', $classes );
$classes = preg_replace( '/^((menu|page)[-_\w+]+)+/', '', $classes );
$classes[] = 'menu-' . $slug;
$classes = array_unique( $classes );
return array_filter( $classes, 'dw_focus_is_element_empty' );
}
add_filter( 'nav_menu_css_class', 'dw_focus_nav_menu_css_class', 10, 2 );
add_filter( 'nav_menu_item_id', '__return_null' );
/**
* Clean up wp_nav_menu_args
*
* Remove the container
* Use DW_Focus_Nav_Walker() by default
*/
function dw_focus_nav_menu_args( $args = '' ) {
$dw_focus_nav_menu_args['container'] = false;
if ( ! $args['items_wrap'] ) {
$dw_focus_nav_menu_args['items_wrap'] = '<ul class="%2$s">%3$s</ul>';
}
if ( current_theme_supports( 'bootstrap-top-navbar' ) && ! $args['depth'] ) {
$dw_focus_nav_menu_args['depth'] = 2;
}
if ( ! $args['walker'] ) {
$dw_focus_nav_menu_args['walker'] = new DW_Focus_Nav_Walker();
}
return array_merge( $args, $dw_focus_nav_menu_args );
}
add_filter( 'wp_nav_menu_args', 'dw_focus_nav_menu_args' );
function dw_focus_is_element_empty( $element ) {
$element = trim( $element );
return empty( $element ) ? false : true;
}
add_action( 'wp_ajax_dw_focus_must_read_articles', 'dw_focus_must_read_articles' );
add_action( 'wp_ajax_nopriv_dw_focus_must_read_articles', 'dw_focus_must_read_articles' );
if ( ! function_exists( 'dw_focus_must_read_articles' ) ) {
function dw_focus_must_read_articles(){
if ( isset( $_REQUEST['max'] ) ) {
$max_number_posts = sanitize_key( $_REQUEST['max'] );
}
$post_array = array(
'posts_per_page' => $max_number_posts,
'order' => 'DESC',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
);
$r = new WP_Query( $post_array );
if ( $r->have_posts() ) : ?>
<div class="text-left">
<strong><?php echo esc_html( date_i18n( get_option( 'date_format' ) ) ); ?></strong>
<div class="row">
<?php $i = 1; while ( $r->have_posts() ) : $r->the_post();?>
<div class="col-md-4">
<article <?php post_class(); ?>>
<div class="entry-thumbnail"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array( 40, 40 ) ) ?></a></div>
<div class="entry-title"><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></div>
</article>
</div>
<?php if ( 0 === $i % 3 ) : ?></div><div class="row"><?php endif; ?>
<?php $i++; endwhile; ?>
</div>
</div>
<?php
wp_reset_postdata();
endif;
die();
}
}