Wordpress Sub-nav

Shot_1275006764

8 Responses

  1. Dave Shea Dave Shea

    I spent a much bigger chunk of my day than I had anticipated getting a reliable third-level nav component built in Wordpress. Either the third-level wouldn't show up, or *only* the third-level would show up, or the entire nav tree would show up on every page, or the second-level pages would only show the second-level nav and the third-level pages would only show the third-level nav.

    The code I ended up with was simple; figuring out this code was not.

    $anc = get_post_ancestors($post);
    // if there are more than one ancestor pages, show the section tree
    if (count($anc) > 1) {
    wp_list_pages("title_li=&child_of=$anc[1]&depth=2");

    // otherwise show the flat section nav
    } else {
    wp_list_pages("title_li=&child_of=$parent&depth=2");
    }

    Addendum: looks like I included an undefined variable. $parent looks like this (and makes me think there's a more elegant way to combine both of these):

    if(empty($wp_query->post->post_parent)) {
    $parent = $wp_query->post->ID;
    } else {
    $parent = $wp_query->post->post_parent;
    }

    almost 4 years ago

  2. Dave Rau Dave Rau

    Very useful code Dave, thanks for sharing.

    This nav looks great, too! Nice icons here to draw the eye and invite clicks.

    almost 4 years ago

  3. Terry Acker Terry Acker

    I probably will greatly value this once I begin my next WP theme. Thanks ahead of time!

    almost 4 years ago

  4. Rogie King Rogie King

    Very smooth design Dave!

    almost 4 years ago

  5. Ahmed Chergaoui Ahmed Chergaoui

    Thanks for the tip!

    almost 4 years ago

  6. Gedy Rivera Gedy Rivera

    Thanks for sharing this Dave. Your design is sweet and I especially love the shadow behind the small white arrow. It's the perfect detail.

    almost 4 years ago

  7. Matthew Anderson Matthew Anderson

    That subtle drop-shadow under the arrow is awesome!

    almost 4 years ago

  8. Tom Leadbetter Tom Leadbetter

    Thanks for sharing Dave, I just stumbled across this page.

    But moments ago I found this superb plugin:
    http://wordpress.org/extend/plugins/simple-section-navigation/

    Might come in handy for you or other?

    over 3 years ago

keyboard shortcuts: previous shot next shot L or F like