Added option for cleaner menu output - fixes #33
This commit is contained in:
13
header.php
13
header.php
@@ -44,12 +44,21 @@
|
|||||||
<?php roots_header_inside(); ?>
|
<?php roots_header_inside(); ?>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a id="logo" href="<?php echo home_url(); ?>/"><img src="<?php echo get_template_directory_uri(); ?>/img/logo.png" width="300" height="75" alt="<?php bloginfo('name'); ?>"></a>
|
<a id="logo" href="<?php echo home_url(); ?>/"><img src="<?php echo get_template_directory_uri(); ?>/img/logo.png" width="300" height="75" alt="<?php bloginfo('name'); ?>"></a>
|
||||||
|
<?php if ($roots_options['clean_menu']) { ?>
|
||||||
<nav id="nav-main" role="navigation">
|
<nav id="nav-main" role="navigation">
|
||||||
<?php wp_nav_menu(array('theme_location' => 'primary_navigation')); ?>
|
<?php wp_nav_menu(array('theme_location' => 'primary_navigation', 'walker' => new roots_nav_walker())); ?>
|
||||||
</nav>
|
</nav>
|
||||||
<nav id="nav-utility">
|
<nav id="nav-utility">
|
||||||
<?php wp_nav_menu(array('theme_location' => 'utility_navigation')); ?>
|
<?php wp_nav_menu(array('theme_location' => 'utility_navigation', 'walker' => new roots_nav_walker())); ?>
|
||||||
</nav>
|
</nav>
|
||||||
|
<?php } else { ?>
|
||||||
|
<nav id="nav-main" role="navigation">
|
||||||
|
<?php wp_nav_menu(array('theme_location' => 'primary_navigation')); ?>
|
||||||
|
</nav>
|
||||||
|
<nav id="nav-utility">
|
||||||
|
<?php wp_nav_menu(array('theme_location' => 'utility_navigation')); ?>
|
||||||
|
</nav>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<?php roots_header_after(); ?>
|
<?php roots_header_after(); ?>
|
||||||
|
|||||||
@@ -347,4 +347,44 @@ function roots_nav_menu_args($args = '') {
|
|||||||
|
|
||||||
add_filter('wp_nav_menu_args', 'roots_nav_menu_args');
|
add_filter('wp_nav_menu_args', 'roots_nav_menu_args');
|
||||||
|
|
||||||
|
class roots_nav_walker extends Walker_Nav_Menu {
|
||||||
|
function start_el(&$output, $item, $depth, $args) {
|
||||||
|
global $wp_query;
|
||||||
|
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
|
||||||
|
|
||||||
|
$slug = sanitize_title($item->title);
|
||||||
|
|
||||||
|
$class_names = $value = '';
|
||||||
|
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
|
||||||
|
|
||||||
|
$classes = array_filter($classes, 'check_current');
|
||||||
|
|
||||||
|
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
|
||||||
|
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
|
||||||
|
|
||||||
|
$id = apply_filters( 'nav_menu_item_id', 'menu-' . $slug, $item, $args );
|
||||||
|
$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
|
||||||
|
|
||||||
|
$output .= $indent . '<li' . $id . $class_names . '>';
|
||||||
|
|
||||||
|
$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 ) .'"' : '';
|
||||||
|
|
||||||
|
$item_output = $args->before;
|
||||||
|
$item_output .= '<a'. $attributes .'>';
|
||||||
|
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
|
||||||
|
$item_output .= '</a>';
|
||||||
|
$item_output .= $args->after;
|
||||||
|
|
||||||
|
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_current($val) {
|
||||||
|
return preg_match('/current-menu/', $val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -277,4 +277,4 @@ function roots_add_htaccess($rules) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_action('mod_rewrite_rules', 'roots_add_htaccess');
|
add_action('mod_rewrite_rules', 'roots_add_htaccess');
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
function roots_admin_enqueue_scripts($hook_suffix) {
|
function roots_admin_enqueue_scripts($hook_suffix) {
|
||||||
if ($hook_suffix != 'appearance_page_theme_options')
|
if ($hook_suffix !== 'appearance_page_theme_options')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$home_url = home_url();
|
$home_url = home_url();
|
||||||
@@ -80,7 +80,8 @@ function roots_get_default_theme_options() {
|
|||||||
'container_class' => 'span-24',
|
'container_class' => 'span-24',
|
||||||
'main_class' => 'span-14 append-1',
|
'main_class' => 'span-14 append-1',
|
||||||
'sidebar_class' => 'span-8 prepend-1 last',
|
'sidebar_class' => 'span-8 prepend-1 last',
|
||||||
'google_analytics_id' => ''
|
'google_analytics_id' => '',
|
||||||
|
'clean_menu' => true
|
||||||
);
|
);
|
||||||
|
|
||||||
return apply_filters('roots_default_theme_options', $default_theme_options);
|
return apply_filters('roots_default_theme_options', $default_theme_options);
|
||||||
@@ -156,6 +157,29 @@ function theme_options_render_page() {
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr valign="top"><th scope="row"><?php _e('Cleanup Menu Output', 'roots'); ?></th>
|
||||||
|
<td>
|
||||||
|
<fieldset><legend class="assistive-text"><span><?php _e('Cleanup Menu Output', 'roots'); ?></span></legend>
|
||||||
|
<div class="layout">
|
||||||
|
<label class="description">
|
||||||
|
<input type="radio" name="roots_theme_options[clean_menu]" value="yes" <?php checked($roots_options['clean_menu'], true); ?> />
|
||||||
|
<span>
|
||||||
|
<?php echo _e('Yes', 'roots'); ?>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="layout">
|
||||||
|
<label class="description">
|
||||||
|
<input type="radio" name="roots_theme_options[clean_menu]" value="no" <?php checked($roots_options['clean_menu'], false); ?> />
|
||||||
|
<span>
|
||||||
|
<?php echo _e('No', 'roots'); ?>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@@ -191,7 +215,10 @@ function roots_theme_options_validate($input) {
|
|||||||
if (isset($input['google_analytics_id']))
|
if (isset($input['google_analytics_id']))
|
||||||
$output['google_analytics_id'] = $input['google_analytics_id'];
|
$output['google_analytics_id'] = $input['google_analytics_id'];
|
||||||
|
|
||||||
|
if (isset($input['clean_menu']))
|
||||||
|
$output['clean_menu'] = ($input['clean_menu'] === 'yes') ? true : false;
|
||||||
|
|
||||||
return apply_filters('roots_theme_options_validate', $output, $input, $defaults);
|
return apply_filters('roots_theme_options_validate', $output, $input, $defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user