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 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 } ?>
share|improve this question
    
Can you post your conditional for showing it on the child pages? –  NW Tech Jan 17 '13 at 21:49

1 Answer 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.""); 
share|improve this answer

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.