0

I am using wp_list_pages to show the page structure on a website. For instance, if I use this code, it will show me the complete child / grandparent heirarchy of the current page the user is on:

wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); 

So this would generate something like this: (keep in mind, the user is on a page called About, which is the parent)

enter image description here

This works great, but if you were to click on any grandparent page (Like Partners), the wp_list_pages code does not work. I have implemented a conditional statement which will use different code on a child page then the grandparent page. So that said, I have the child pages working great. I just need to figure out how to display this same exact menu on the grandparent pages.

Any idea?

Here is how the conditional work:

<?php if( count(get_post_ancestors($post->ID)) == 2 && $post->post_parent){ ?> I need new code here <?php } elseif(count(get_post_ancestors($post->ID)) == 1 && $post->post_parent){ $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); echo $children; } else { ?> <li>Parent Page</li> <?php } ?> 
1
  • Can you post your conditional for showing it on the child pages? Commented Jan 17, 2013 at 21:49

1 Answer 1

1

In the area above where it says "I need new code here" I simply grabbed the ID using get_post_ancestors like so:

$parent = array(); $parent = get_post_ancestors($post->ID); $lastNum = end($parent); wp_list_pages("title_li=&child_of=".$lastNum.""); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.