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 know this is going to be simple but I can't work it out.

I want to create a nav in the footer listing each page and it's child pages.

It will look something like this

    <ul>
      <li><a href="parent.html">Parent</a></li>
      <li><a href="childone.html">Child One</a></li>
      <li><a href="childtwo.html">Child Two</a></li>
      <li><a href="childthree.html">Child Three</a></li>
    </ul>  

I'm using this code to do it.

    <div id="footerLinks">
        <?php
        $args = array(
            'sort_column' => 'menu_order',
            'parent' => 0,
            );
        $pages = get_pages($args);
        foreach($pages as $page){
            ?>
            <ul>
                <li>
                        <a href="<?php echo $page->permalink; ?>"><?php echo $page->post_title;?> </a> 
                </li>
                <?php  
                wp_list_pages('title_li=&depth=1&child_of='.$page->ID.'');
                ?>  
            </ul>
            <?php
            }
        ?>
    </div>

My problem is getting the permalink to the parent page.

    <a href="<?php echo $page->permalink; ?>"><?php echo $page->post_title;?> </a> 

How do I get the permalink in this situation?

share|improve this question
    
While this question probably was in scope for both sites, please refrain from posting simultaneous duplicates on other SE network sites in the future. –  Johannes Pille Mar 31 '13 at 11:55

1 Answer 1

up vote 3 down vote accepted

$page->post_parent is the ID of the parent page. So

get_permalink( $page->post_parent );

… should do it.

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.