0

I am currently developing a new WordPress theme employed on the basis of twitters bootstrap build.

To use the menu Custom Navbar, I've followed the instructions of goodandorgreat.

https://gist.github.com/1597994

My problem now is that menu items with submenus are also clickable.

That should not be so. What could I do here?

header.php Setup:

<div class="navbar">
<div class="navbar-inner">
    <div class="container">

        <!-- Optional: Button zum Menü einklappen auf Mobilgeräten, benötigt responsive.css -->
        <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </a>
        <!-- Ende Button -->

        <div class="nav-collapse">
        <?php

        $args = array(
            'theme_location' => 'top-bar',
            'menu' => 'main-menu', 
            'container_class' => 'nav-collapse',
            'menu_class'     => 'nav',
            'menu_id' => 'main-menu',
            'walker'     => new Bootstrap_Walker_Nav_Menu()
        );

        wp_nav_menu($args);

        ?>

        </div>
    </div>
</div>

I dont want handle that with entrie url's like "#".

1

I am admittedly out on a limb here because to test this I'd have to install your code and create some menus to test it with, but...

Look in the Bootstrap_Walker_Nav_Menu code. Find this:

$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= ($args->has_children) ? ' <b class="caret"></b></a>' : '</a>';
$item_output .= $args->after;

I believe that what you want is to wrap the code that creates the anchors in a conditional like:

if (!$args->has_children) {
    $item_output .= '<a'. $attributes .'>';
}
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= ($args->has_children) ? ' <b class="caret"></b>' : '';
if (!$args->has_children) {
    $item_output .= '</a>';
}
$item_output .= $args->after;
  • Looking at the source of the page, this seem to be doing what I thought that you wanted. That is, only the lowest level, childless list items have anchor tags. Your theme's CSS seems to need those anchors for the dropdowns to work. You will need to rewrite that CSS. If I have misunderstood, please edit your question to clarify. – s_ha_dum Nov 3 '12 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.