[wp-hackers] Multi-level page nav

Will Anderson wp-hackers at itsananderson.com
Sat Aug 1 20:41:45 UTC 2009


On Sat, Aug 1, 2009 at 4:28 PM, Joel Fisher <joelfisher at gmail.com> wrote:

> I am trying to do this in WP..
>
>
> Parent 1   PARENT 2    Parent 3
>
> Child 1
> Child 2
> CHILD 3
>  Childlevel3 1
>  Childlevel3 2
>  Childlevel3 3
> Child 4
> Child 5
>
>
> Seems pretty easy with a ..
>
> <?php
>  $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
>  if ($children) { ?>
>  <ul>
>  <?php echo $children; ?>
>  </ul>
>  <?php
>  } else {
> // your else stuff
>  }
> ?>
>
>
> However, the kicker here..Child 2 and Child 4 each have third level
> childs, but I don't want them to show.
>
> So, I thinking some sort of if else..
>
> <?php
>  $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
> <?php if (is_page('Child3') || $post->post_parent=="20") : ?>
>  <ul>
>  <?php echo $children; ?>
>  </ul>
>  <?php
>  } else {
> // your else stuff
>  }
> ?>
>
> But I can't seem to get the correct logic in place to ONLY show the
> sub-childs of a particular section in-line with the child pages but
> not show the other sub-pages third level childs...
>
> Confusing, but an interesting problem. Any suggestions?
>
>
>
> joel.fisher
> www.flushinc.com
>
> Linkedin: http://www.linkedin.com/in/jfisher
> Follow: www.twitter.com/joelmoney
>


I could be missing something here, but wouldn't specifying a depth as an
argument solve your problem? If you look at the
Codex<http://codex.wordpress.org/Template_Tags/wp_list_pages> for
wp_list_pages, there's an argument you can specify which tells WordPress how
far down to recurse. I *think* this will do what you're looking for.
eg:

$children =
wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');

-- 
Will Anderson
http://www.itsananderson.com/


More information about the wp-hackers mailing list