Grow your CSS skills. Land your dream job.

[Solved] WordPress – Add Class to Child UL in the Nav

  • # February 8, 2010 at 10:07 pm

    I stumbled on Chris’s great Simple jQuery Dropdown menu [http://css-tricks.com/Simple-jQuery-Dropdowns/], and it works just the way I want it to both in IE and "real" browsers. However, it requires a class added to the child ul:

    <ul class="dropdown">
    <li><a href="facilities.php">Facilities</a>
    <ul class="sub_menu">

    I suspect there is a way to add this in the functions file, but it’s beyond my copy-paste-tinker PHP skills to create the function :oops:
    How do I do this?

    # February 10, 2010 at 10:59 am

    Mike Little of zed1.com furnished a solution on a LinkedIn forum:

    In the theme functions file:

    class My_Walker_Page extends Walker_Page {
    function start_lvl(&$output, $depth) {
    $indent = str_repeat("t", $depth);
    if (0 == $depth)
    $output .= "n$indent<ul class="sub_menu">n";
    else
    $output .= "n$indent<ul>n";
    }
    }

    In the header file where menu is to appear:

    <ul class="dropdown"><?php $walker = new My_Walker_Page;
    wp_list_pages(array(‘title_li’=>”, ‘depth’ => 2, ‘walker’ => $walker)); ?></ul>

    Mucho gracias to Mike Little, who was a founding member of the WordPress team.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".