0

I'm trying to create a second level navigation in WordPress. I've found lots of examples, but none of them seem to do exactly what I want. This code below has me almost there, but I want an active class or better yet a way to only show the sub navigation if I'm on it. It would be great it WordPress had a depth_start option along with depth.

Example:

link1
link2 (active class)
  link2-1
  link2-2
  link2-3
link3
link4

Code so far:

<?php

$parent = array_reverse(get_post_ancestors($post->ID));
$first_parent = get_page($parent[0]);

$args = array(
    'depth'        => 0,
    'child_of'     => $first_parent->ID,
    'title_li'     => __($first_parent->post_title),
    'sort_column'  => 'menu_order',
); ?>

<nav class="sidebar">
    <ul>
        <?php wp_list_pages( $args ); ?> 
    </ul>
</nav>

1 Answer 1

0

For now I have decided to use a CSS solution. I realized with the code above I do actually have classes I can work with. For example if you had this navigation in a you could use something like this.

nav.sidebar li li li {
    display: none;
}
nav.sidebar li li.current_page_item > ul > li, nav.sidebar li li.current_page_ancestor > ul > li {
    display: block;
}

While not ideal, it gets the job done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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