Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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