Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] WordPress – Add Class to Child UL in the Nav

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #27931
    RayGulick
    Member

    I stumbled on Chris’s great Simple jQuery Dropdown menu [https://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?

    #70719
    RayGulick
    Member

    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)
  • The forum ‘Back End’ is closed to new topics and replies.